In @std/esm 0.19.0 through 0.19.2, nyc generates a "ReferenceError: require is not defined" from chai/index.js:1 (
module.exports = require('./lib/chai');).
mocha --exit -r @std/esm test/unit/*.js is finenyc mocha --exit -r @std/esm test/unit/*.js with @std/esm version 0.18.0 is finenyc mocha --exit -r @std/esm test/unit/*.js with @std/esm v0.19.0+ failsVersions: @std/esm – 0.19.2, nyc – 11.4.1, chai – 4.1.2.
@std/esm options (in package.json): @std/esm: { "esm": "js" }.
Stack trace:
$ nyc mocha --exit -r @std/esm test/unit/*.js
ReferenceError: module is not defined
at Object.<anonymous> (file://~/app/node_modules/chai/index.js:1)
at module.exports (file://~/app/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)
at ~/app/node_modules/nyc/node_modules/append-transform/index.js:62:4
at T.replacementCompile (file://~/app/node_modules/nyc/node_modules/append-transform/index.js:58:13)
at module.exports (file://~/app/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)
at ~/app/node_modules/nyc/node_modules/append-transform/index.js:62:4
at Object.<anonymous> (file://~/app/node_modules/nyc/node_modules/append-transform/index.js:62:4)
at ~/app/test/unit/auto-identifier-tests.js:1
at Object.<anonymous> (file://~/app/test/unit/auto-identifier-tests.js:1)
at Module._compile (module.js:635:30)
at Module.replacementCompile (file://~/app/node_modules/nyc/node_modules/append-transform/index.js:58:13)
at Object.<anonymous> (file://~/app/node_modules/nyc/node_modules/append-transform/index.js:62:4)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at ~/app/node_modules/mocha/lib/mocha.js:231:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (file://~/app/node_modules/mocha/lib/mocha.js:228:14)
at Mocha.run (file://~/app/node_modules/mocha/lib/mocha.js:536:10)
at Object.<anonymous> (file://~/app/node_modules/mocha/bin/_mocha:573:18)
at Module._compile (module.js:635:30)
at Module.replacementCompile (file://~/app/node_modules/nyc/node_modules/append-transform/index.js:58:13)
at module.exports (file://~/app/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)
at Object.<anonymous> (file://~/app/node_modules/nyc/node_modules/append-transform/index.js:62:4)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at runMain (file://~/.node-spawn-wrap-4314-1f9023bc8504/node:68:10)
at Function.<anonymous> (file://~/.node-spawn-wrap-4314-1f9023bc8504/node:171:5)
at Object.<anonymous> (file://~/app/node_modules/nyc/bin/wrap.js:23:4)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at ~/.node-spawn-wrap-4314-1f9023bc8504/node:178:8
at Object.<anonymous> (file://~/.node-spawn-wrap-4314-1f9023bc8504/node:181:3)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
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 | |
----------|----------|----------|----------|----------|----------------|
Other tests using supertest fail with "ReferenceError: require is not defined".
Thanks for the report @chrisveness!
Could you create a simple repro repo for me to check out?
I'll see what I can put together.
This seems to be resolved on master.
Spoke too soon. I can repro this.
Update:
Patched https://github.com/standard-things/esm/commit/99b4b2ea4f0f461a3b9853d6fc4f26a5c4b6b073.
v0.19.3 is released :tada:
That's sorted it: thanks for the fast response – fantastic!
FYI, I'm still having various problems with nyc, including generating
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | Unknown | Unknown | Unknown | Unknown | |
----------|----------|----------|----------|----------|----------------|
but it's very inconsistent behaviour, and I've no idea whether it's related to @std/esm or not. I'll see if I can put together something reproducible.