auth0-nextjs-samples icon indicating copy to clipboard operation
auth0-nextjs-samples copied to clipboard

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

Open bennycode opened this issue 1 year ago • 0 comments

Checklist

  • [X] I have looked into the Readme and have not found a suitable solution or answer.
  • [X] I have searched the issues and have not found a suitable solution or answer.
  • [X] I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • [X] I agree to the terms within the Auth0 Code of Conduct.

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

bennycode avatar Jul 16 '24 09:07 bennycode