The present invention relates to: a method for producing a 7H-pyrrolo[2,3-d]pyrimidine derivative which is useful as a Janus kinase (JAK) inhibitor; a cocrystal of the derivative; a method for producing the cocrystal; and a method for purifying the 7H-pyrrolo[2,3-d]pyrimidine derivative using the cocrystal. The present invention provides a method for producing, for example, 3-[(3S,4R)-3-methyl-6(7H-pyrrolo[2,3-d]pyrimidin-4-yl)-1,6-diazaspiro[3.4]octan-1-yl]-3-oxopropanenitrile, wherein use is made of a cocrystal of 3-[(3S,4R)-3-methyl-6-(7H-pyrrolo[2,3-d]pyrimidin-4-yl)-1,6-diazaspiro[3.4]octan-1-yl]-3-oxopropanenitrile with 3,5-dimethylpyrazole.