Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cedx opened this issue Oct 14, 2019 · 13 comments
Closed

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

cedx opened this issue Oct 14, 2019 · 13 comments

Comments

@cedx
Copy link

cedx commented Oct 14, 2019

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
@coreyfarrell
Copy link
Member

Can you give nyc 15.0.0-beta.0 a try? The issue you are seeing here is the result of spawn-wrap having trouble under Windows. The next version of nyc will by-pass spawn-wrap in favor of a different method.

Please note that "type": "module" may still potentially be problematic and nyc can not currently support running ES modules in --experimental-modules mode (node.js does not provide API's required to do so).

@cedx
Copy link
Author

cedx commented Oct 14, 2019

Indeed, using nyc 15.0.0-beta.0 fixes the issue!
Thanks a lot. So, I only have to wait for the next release 😄

@cedx cedx closed this as completed Oct 14, 2019
TimothyJones added a commit to pact-foundation/pact-js that referenced this issue Oct 29, 2019
TimothyJones added a commit to pact-foundation/pact-js that referenced this issue Oct 29, 2019
TimothyJones added a commit to pact-foundation/pact-js that referenced this issue Oct 29, 2019
@Gerrit0
Copy link

Gerrit0 commented Nov 9, 2019

I've also run into this, what is the 15.0 release waiting on? Is there something I can do to help get it released sooner?

@coreyfarrell
Copy link
Member

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.

Gerrit0 added a commit to pmconne/typedoc that referenced this issue Nov 9, 2019
Gets around istanbuljs/nyc#1205 breaking on Windows with Node 12.
Gerrit0 added a commit to TypeStrong/typedoc that referenced this issue Nov 9, 2019
Gets around istanbuljs/nyc#1205 breaking on Windows with Node 12.
@sramam
Copy link

sramam commented Dec 12, 2019

I need to get this working on macosx/windows/linux.

Upgrading to 15.0.0-beta.0 as suggested on macosx results in:

> cross-env NODE_ENV=test nyc -r lcov -r text-summary -r json-summary ava --verbose

Class constructor TestExclude cannot be invoked without 'new'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `cross-env NODE_ENV=test nyc -r lcov -r text-summary -r json-summary ava --verbose`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/sramam/.npm/_logs/2019-12-12T22_37_55_128Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `npm-run-batch`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/sramam/.npm/_logs/2019-12-12T22_37_55_203Z-debug.log

Digging in, it seems this is a problem on 15.0.0-beta.0 with needing testExclude constructor being invoked with new. It does seem to be fixed in master. Is there a more recent beta release I should be using?

@sramam
Copy link

sramam commented Dec 12, 2019

I was able to verify on macosx that adding the new fixes the problem with 15.0.0-beta.0

@coreyfarrell
Copy link
Member

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

charleszipp added a commit to TsuyoshiUshio/azure-pipelines-tasks-terraform that referenced this issue Feb 7, 2020
the version of nyc that was being used had defect (istanbuljs/nyc#1205) that was preventing ci from passing
raphinesse added a commit to raphinesse/eslint-plugin-import that referenced this issue Feb 7, 2020
@ljharb
Copy link
Contributor

ljharb commented Feb 7, 2020

Is there any workaround to upgrading to nyc 15 to fix this? Is it caused by a spawn-wrap update that can be avoided by pinning it?

@coreyfarrell
Copy link
Member

In eslint-plugin-import you are using [email protected] which actually has [email protected] bundled (1.4.2 was released on Dec 5 2017). What happens if you force your CI to test 12.10.0 on Windows, does this currently pass? I ask since this report seems to indicate the problem started with the upgrade to node.js 12.11.0, not with any nyc update. Not suggesting this is a solution, just seeking confirmation of the source of the problem.

As far as spawn-wrap I'm not sure 2.x even fixes the issue, by default nyc 15 does not use spawn-wrap as it is unreliable (especially on Windows). nyc 15 instead uses node-preload which injects --require flags into NODE_OPTIONS (a node.js 8+ feature). So I'm not aware of any work around.

@ljharb
Copy link
Contributor

ljharb commented Feb 7, 2020

I'll try 12.10, thanks, that's a good suggestion.

ljharb pushed a commit to raphinesse/eslint-plugin-import that referenced this issue Feb 7, 2020
@ljharb
Copy link
Contributor

ljharb commented Feb 7, 2020

Doesn't look like appveyor offers a way to do that :-/

ljharb pushed a commit to raphinesse/eslint-plugin-import that referenced this issue Feb 7, 2020
ljharb pushed a commit to raphinesse/eslint-plugin-import that referenced this issue Feb 8, 2020
@tvkit
Copy link

tvkit commented Mar 14, 2020

I experienced the aforementioned issues and wanted to mention that 15.0.0 works for me.

ryantmer added a commit to Brightspace/node-siren-parser that referenced this issue Feb 4, 2021
There are a bunch of outdated packages here, but looks like there's an
issue with this version of `nyc` specifically,
istanbuljs/nyc#1205. Updating just that for
now, but should really get things updated in general here, as well as
move to GH Actions.

(Also removed `cross-env` since it's doing nothing of value here.)
@Methuselah96
Copy link

FWIW, I found that spawn-wrap 1.4.3 fixed the issues I was seeing (which was happening even on older versions of Node).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants