[Node.js 12.11+ and Windows 10] Error: Cannot find module "node"
See original GitHub issueMy use case: I have TypeScript projects that are coded as ES modules (for example: cedx/coveralls.js or cedx/which.js). They are intended to run on Node.js v12.x only and use the field "type": "module"
in the package.json
file (i.e. the used file extension is .js
, not .mjs
).
For the tests and code coverage, I’m using ts-node
to avoid compiling the projects while I develop them. So, in test environment, the projects are compiled on the fly as CommonJS modules (ts-node
does not support ES modules).
The command line used:
nyc --nycrc-path=etc/nyc.json node_modules/.bin/mocha --config=etc/mocha.json "test/**/*.ts"
This configuration worked fine on Node v12.10.x and below, but since v12.11.0 the tests don’t run anymore on Windows and produce this error:
internal/modules/esm/default_resolve.js:82 let url = moduleWrapResolve(specifier, parentURL);
^
Error: Cannot find module C:\Projets\js\enum.js\node imported from C:\Projets\js\enum.js\
at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:82:13) at Loader.resolve (internal/modules/esm/loader.js:73:33) at Loader.getModuleJob (internal/modules/esm/loader.js:147:40) at Loader.import (internal/modules/esm/loader.js:131:28) at internal/modules/cjs/loader.js:1015:27 at processTicksAndRejections (internal/process/task_queues.js:93:5) { code: 'ERR_MODULE_NOT_FOUND' }
If I run the tests without code coverage, no error occurs:
mocha --config=etc/mocha.json "test/**/*.ts"
=> everything is OK.
Link to bug demonstration repository
https://github.com/cedx/enum.js
Expected Behavior
The tests succeed to run and the code coverage is collected.
Observed Behavior
The tests fail to run if code coverage is collected with nyc
.
Troubleshooting steps
- this issue still occurs when I put
cache: false
in my nyc config - this issue only appears on Windows platform. On a Linux platform, everything is OK.
Environment Information
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz
Memory: 2.41 GB / 7.92 GB
Binaries:
Node: 12.12.0 - C:\Program Files\Node.js\node.EXE
npm: 6.11.3 - C:\Program Files\Node.js\npm.CMD
npmPackages:
nyc: ^14.1.1 => 14.1.1
source-map-support: ^0.5.13 => 0.5.13
ts-node: ^8.4.1 => 8.4.1
typescript: ^3.6.4 => 3.6.4
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:12 (7 by maintainers)
Top GitHub Comments
please use 15.0.0-beta.3, there was a late breaking change to test-exclude.
nyc 15 is a complex release with major changes. The tracking ticket is #1104 so you can subscribe to that for progress updates. Getting close to the final stretch I just need to get some more testing with major ecosystem projects (testing frameworks). Beyond that it’s really a matter of me having time to do the release and support issues that will occur upon release (not everyone reads the CHANGELOG.md and some assume that breaking changes are bugs).
If nyc 15.0.0-beta.0 fixes bugs for you then my advice is to use it. You may want to pin to
=15.0.0-beta.0
just in case we need to make a breaking change - I don’t expect this but it’s not ruled out until final 15.0.0 release is made.