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

ERR_UNKNOWN_FILE_EXTENSION with node 8.9.0 and ECMAScript module syntax #708

Closed
rogerta opened this issue Nov 4, 2017 · 6 comments
Closed

Comments

@rogerta
Copy link

rogerta commented Nov 4, 2017

Expected Behavior

I'd like to get code coverage when I write code (and unit tests) with ECMAScript module syntax.

Observed Behavior

Error is thrown:

Error [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension: /home/rogerta/.node-spawn-wrap-26280-72eb4eed3ba9/node
    at exports.resolve (internal/loader/ModuleRequest.js:126:13)
    at Loader.resolve (internal/loader/Loader.js:48:40)
    at Loader.getModuleJob (internal/loader/Loader.js:76:40)
    at Loader.import (internal/loader/Loader.js:98:28)
    at module.js:457:29
    at Function.Module._load (module.js:458:7)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

Bonus Points! Code (or Repository) that Reproduces Issue

https://github.com/rogerta/node-tap-esm.git

Repro steps:

$ git clone https://github.com/rogerta/node-tap-esm.git
$ cd node-tap-esm
$ npm install
$ npm run cesm
> [email protected] cesm /home/rogerta/src/tap
> nyc -e .mjs node --experimental-modules foo_test.mjs

(node:26286) ExperimentalWarning: The ESM module loader is experimental.
Error [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension: /home/rogerta/.node-spawn-wrap-26280-72eb4eed3ba9/node
    at exports.resolve (internal/loader/ModuleRequest.js:126:13)
    at Loader.resolve (internal/loader/Loader.js:48:40)
    at Loader.getModuleJob (internal/loader/Loader.js:76:40)
    at Loader.import (internal/loader/Loader.js:98:28)
    at module.js:457:29
    at Function.Module._load (module.js:458:7)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files |  Unknown |  Unknown |  Unknown |  Unknown |                |
----------|----------|----------|----------|----------|----------------|
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] cesm: `nyc -e .mjs node --experimental-modules foo_test.mjs`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] cesm 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!     /home/rogerta/.npm/_logs/2017-11-04T03_49_30_607Z-debug.log

Forensic Information

Operating System: Linux argon 4.8.0-59-generic #64-Ubuntu SMP Thu Jun 29 19:38:34 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Environment Information: https://gist.github.com/rogerta/54ac869a4f784a848b7f620cc8ce8d4e

@bcoe
Copy link
Member

bcoe commented Nov 27, 2017

@rogerta .mjs files are not yet supported; There's been a pretty significant change to how module loading works, which breaks some of the underlying behavior of nyc. I'm working hard on correcting this, and you can track progress here:

nodejs/node#17337

@bcoe bcoe added the triaged label Nov 27, 2017
@rogerta
Copy link
Author

rogerta commented Nov 27, 2017

Cool, thanks Benjamin.

@jdalton
Copy link

jdalton commented Dec 5, 2017

@rogerta
You might check out @std/esm.
It works with the nyc --require option without the --experimental-modules flag.

@rogerta
Copy link
Author

rogerta commented Dec 5, 2017

Thanks John, I'll check it out. My workaround for now is to compile my typescript code twice: once with ESM syntax for production and another time with CJS syntax for testing and coverage. This sounds like a better option until nodejs/node#17337 is fixed.

@stale stale bot added the wontfix label Jan 6, 2019
@stale
Copy link

stale bot commented Mar 7, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 7, 2019
@coreyfarrell
Copy link
Member

I just updated tap in your repo and tested, I'm not getting an error from npm run cesm. That said I'm also not getting coverage. For now I recommend using nyc -i esm as suggested by @jdalton. node --experimental-modules is just what it says - experimental. I've opened #1013 as a separate issue to look into why nyc isn't doing anything in that mode, I suspect the new module loader is bypassing the CJS loader system so our hooks are not working, nyc --show-process-tree=true does record information about the sub-process so I'm pretty sure that means spawn-wrap is still running and we're hooking the CJS system, but the ESM system is bypassing our hooks.

@JaKXz JaKXz removed the wontfix label Mar 7, 2019
@istanbuljs istanbuljs deleted a comment from stale bot Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants