auth0-samples / auth0-nextjs-samples

Auth0 Integration Samples for Next.js Applications
MIT License
127 stars 149 forks source link

TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('SIGINT') #173

Open bennycode opened 3 months ago

bennycode commented 3 months ago

Checklist

Description

When hitting Ctrl + C while the application is running, it won't stop and crash instead with the following error:

(/home/bennycode/dev/bennycode/benny-carbon-hub/node_modules/next/dist/server/lib/start-server.js:208:29)
[0]     at process.emit (node:events:526:35) {
[0]   code: 'ERR_INVALID_ARG_TYPE'
[0] }
[0]  X uncaughtException: TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('SIGINT')

Reproduction

  1. npm run dev
  2. Hit "Ctrl + C" on Windows to stop the processs

Additional context

The problem exists because the samples use the outdated Next.js v13 which has a bug in it's cleanup code:

                const cleanup = (code)=>{
                    debug("start-server process cleanup");
                    server.close();
                    process.exit(code ?? 0);
                };
                process.on("SIGINT", cleanup);

The start-server.js file in Next v13 sends the string SIGINT to process.exit which is not allowed as it is not a number.

It is fixed in Next v14.0.1 -> https://github.com/vercel/next.js/blob/v14.0.1/packages/next/src/server/lib/start-server.ts#L273