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

Missing support for ES modules in node v13. #4102

Closed
npfedwards opened this issue Nov 22, 2019 · 1 comment
Closed

Missing support for ES modules in node v13. #4102

npfedwards opened this issue Nov 22, 2019 · 1 comment

Comments

@npfedwards
Copy link

npfedwards commented Nov 22, 2019

As of node v13.2, ES Modules are no longer hidden behind the --experimental-modules flag. When creating a project with "type":"module" in package.json and running mocha, the following error happens.

Warning: require() of ES modules is not supported.
require() of /path/to/componentTest.js from /path/to/node_modules/mocha/lib/mocha.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 componentTest.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /path/to/package.json.
/path/to/node_modules/mocha/lib/mocha.js:1
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/to/componentTest.js

The offending line being

at Mocha.loadFiles (/path/to/node_modules/mocha/lib/mocha.js:331:14)

It seems to me, either this is a fairly large oversight in mocha, or there's a lack of documentation for this issue (all I've found in google is a comment on a closed issue).

Node: v13.2.0
Mocha: v6.2.2
npm: v6.13.1

@npfedwards
Copy link
Author

Duplicate of #3006

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

1 participant