Node v20: TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('128SIGINT')
anishkny opened this issue · 6 comments
Link to bug demonstration repository
https://github.com/anishkny/nyc-bug-demo
Expected Behavior
Upon pressing Ctrl-C program should exit and coverage information should be generated.
Observed Behavior
npm start
> start
> nyc node index.js
Server running at http://127.0.0.1:3000/
^Cnode:internal/validators:95
throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('128SIGINT')
at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
at ChildProcess.<anonymous> (/Users/anish/workspace/nyc-bug-demo/node_modules/foreground-child/index.js:63:22)
at ChildProcess.emit (node:events:514:28)
at maybeClose (node:internal/child_process:1105:16)
at ChildProcess._handle.onexit (node:internal/child_process:305:5) {
code: 'ERR_INVALID_ARG_TYPE'
}
Node.js v20.8.1
Troubleshooting steps
- Does not happen in Node v18.
- Does not happen if just running server
node index.js
withoutnyc
Environment Information
$ npx envinfo@latest --preset nyc
Need to install the following packages:
envinfo@7.10.0
Ok to proceed? (y)
System:
OS: macOS 14.0
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 132.84 MB / 16.00 GB
Binaries:
Node: 20.8.1 - /usr/local/bin/node
npm: 10.1.0 - /usr/local/bin/npm
npmPackages:
nyc: ^15.1.0 => 15.1.0
Any updates on this? Is this accepted as a pretty severe bug now that Node.js 20 is the current active release?
maybe the main solution will be to bump from foreground-child 2.0.0 to latest version. issue is duplicated here sometimes dead loop · Issue #54 · tapjs/foreground-child · GitHub
I also witnessed this on Node 20, indeed it seems to be an issue with foreground-child
incorrectly treating a string as a number. There are a few options for a fix; I asked the maintainer which he'd prefer: tapjs/foreground-child#54 (comment)
Turns out this is already fixed in the latest version of foreground-child
. I opened #1546 to upgrade the package.
Another reproduction:
npm install nyc@15.1.0 segfault-handler
npx nyc -- node -e 'require("segfault-handler").causeSegfault()'
When I tried to the nyc process with TERM signal, I got the following error:
TypeError: The "code" argument must be of type number. Received type string ('128SIGTERM')
at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
at ChildProcess.<anonymous> (/home/runner/work/shiki-api/shiki-api/node_modules/nyc/node_modules/foreground-child/index.js:63:22)
at ChildProcess.emit (node:events:518:28)
at ChildProcess.emit (node:domain:488:12)
at maybeClose (node:internal/child_process:1105:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5) {
code: 'ERR_INVALID_ARG_TYPE'
}