istanbuljs / test-exclude

test for inclusion or exclusion of paths using globs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

khteh opened this issue · comments

Using node:latest and "nyc": "^15.1.0" bumps into the following error due to your library:

./node_modules/.bin/nyc --reporter=lcov --reporter=text ./node_modules/.bin/mocha tests --timeout 10000 --recursive --check-leaks --exit  --reporter mocha-junit-reporter --reporter-options mochaFile=test_reports/mocha/test-results.xml
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module 'read-pkg-up'
Require stack:
- /root/workspace/node_modules/test-exclude/index.js
- /root/workspace/node_modules/nyc/lib/config-util.js
- /root/workspace/node_modules/nyc/bin/nyc.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/root/workspace/node_modules/test-exclude/index.js:4:19)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/root/workspace/node_modules/test-exclude/index.js',
    '/root/workspace/node_modules/nyc/lib/config-util.js',
    '/root/workspace/node_modules/nyc/bin/nyc.js'
  ]
}

Exited with code exit status 1
./node_modules/.bin/nyc --reporter=lcov --reporter=text ./node_modules/.bin/mocha tests --timeout 10000 --recursive --check-leaks --exit  --reporter mocha-junit-reporter --reporter-options mochaFile=test_reports/mocha/test-results.xml
node:internal/modules/cjs/loader:1109
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /root/workspace/node_modules/read-pkg-up/index.js
require() of ES modules is not supported.
require() of /root/workspace/node_modules/read-pkg-up/index.js from /root/workspace/node_modules/test-exclude/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /root/workspace/node_modules/read-pkg-up/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /root/workspace/node_modules/read-pkg-up/package.json.

    at new NodeError (node:internal/errors:329:5)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1109:13)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/root/workspace/node_modules/test-exclude/index.js:4:19)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32) {
  code: 'ERR_REQUIRE_ESM'
}

Exited with code exit status 1

Any advice and insight is appreciated. sindresorhus/read-package-up#18

I already made it clear that read-pkg-up is not installed or used by nyc or any of it's dependencies. Do not open any further issues with istanbuljs about this problem, troubleshoot your own project to find why you are incorrectly loading read-pkg-up.