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

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /root/workspace/node_modules/read-pkg-up/index.js #18

Closed
khteh opened this issue Apr 4, 2021 · 4 comments

Comments

@khteh
Copy link

khteh commented Apr 4, 2021

Using node:latest bumps into this error:

./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

https://stackoverflow.com/questions/66938218/node-js-read-pkg-up-bumps-into-error-err-require-esm-must-use-import-to-load

@sindresorhus
Copy link
Owner

Duplicate of #17

@khteh
Copy link
Author

khteh commented Apr 4, 2021

I don't understand how reading your README could solve the issue!

/open

@papb
Copy link

papb commented Apr 5, 2021

Not the readme, the release notes. Which in turn bring you to this page.

@alvis
Copy link

alvis commented May 6, 2021

@sindresorhus Would you consider releasing a hybrid version (ESM + common js)?
I use typescript but I have to release my project in hybrid mode for compatibility.
But v8 breaks the possibility because the code can't call read-pkg-up in the commonjs way anymore.

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

4 participants