Growing crystals form a cavity when placed against a wall. The birth of the cavity is observed both by optical microscopy of sodium chlorate crystals (NaClO3) growing in the vicinity of a glass surface, and in simulations with a thin film model. The cavity appears when growth cannot be maintained in the center of the contact region due to an insufficient supply of growth units through the liquid film between the crystal and the wall. We obtain a nonequilibrium morphology diagram characterizing the conditions under which a cavity appears. Cavity formation is a generic phenomenon at the origin of the formation of growth rims observed in many experiments, and is a source of complexity for the morphology of growing crystals in natural environments. Our results also provide restrictions for the conditions under which compact crystals can grow in confinement.