ricokahler / sanity-codegen

Generate TypeScript types from your Sanity.io schemas
sanity-codegen-dev.vercel.app
MIT License
270 stars 19 forks source link

Sanity Codegen process hangs on completion #243

Open alexbchr opened 2 years ago

alexbchr commented 2 years ago

We are currently starting a new project and realized that for some reason, running  sanity-codegen on the project using Node 16.13.2 (or 15.14.0) just hangs. This seems to be a very similar issue to #232.

What I did try locally to fix this is adding a then clause that explicitly exits the process at the end of the CLI process fixes the issue.

In cli.ts file, replacing:

cli().catch((e) => {
  console.error(e);
  process.exit(1);
});

With:

cli().then(() => process.exit(0)).catch((e) => {
  console.error(e);
  process.exit(1);
});

Fixed the hanging issue. Since the last line of cli() gets correctly printed on the culprit computer, the Promise ends fine and everything, but for some unknown reason the process just remains alive. Seems like something in the code is being kept alive that prevents Node from ending the process properly when its work is done. I have no idea what this would be though.

I was able to reproduce on many different computers this time, and even running sanity-codegen inside Github Actions hangs by using the same Node version.

Running sanity-codegen on Node 12 and 14 works fine without any issue.

ricokahler commented 2 years ago

If you wanted to open a PR that includes the process.exit, i'll accept it. This is something that next.js even does so i'm fine with including something similar.