question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Node.js 12.11+ and Windows 10] Error: Cannot find module "node"

See original GitHub issue

My 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:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
coreyfarrellcommented, Dec 12, 2019

please use 15.0.0-beta.3, there was a late breaking change to test-exclude.

2reactions
coreyfarrellcommented, Nov 9, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot find module [Node npm Error Solved] - freeCodeCamp
you're trying to import an item from a module you don't have installed in your project directory; you're importing some things from an...
Read more >
How to resolve "Cannot find module" error in Node - Sabe.io
To fix the Cannot find module error, simply install the missing modules using npm . To so, you can use the following command:...
Read more >
How do I resolve "Cannot find module" error using Node.js?
it seems like when i installed it globally the npm/node-modules folder was empty and i was trying to use ng new project-name it...
Read more >
Previous Releases - Node.js
Version Date V8 npm NODE_MODULE_VERSION Node.js 19.3.0 2022‑12‑14 10.8.168.21 9.2.0 111 Downloads Ä... Node.js 19.2.0 2022‑11‑29 10.8.168.20 8.19.3 111 Downloads Ä... Node.js 19.1.0 2022‑11‑14 10.7.193.20 8.19.3...
Read more >
Install Node.js Locally with Node Version Manager (nvm)
By the end of this tutorial, you should be able to install the nvm command and use it to manage different versions of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found