Error: require of ES Module x from y is not supported
See original GitHub issueGreetings,
Im using oclif to build a cli that runs puppeteer and interacts with a webcomponent library that is published with
"type": "module"
, and am getting this error when i try to import the webcomponent.
Error: require() of ES Module nodemodules/<package>/bundle/src/index.js from
<path>/src/api/core.ts not supported.
index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that
package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to
"type": "commonjs" in <path>/node_modules/<package>/bundle/package.json to treat all .js files as CommonJS
(using .mjs for all ES modules instead).
Code: ERR_REQUIRE_ESM
Which is strange to me since all of the examples use es6 import / export syntax. I assume this has something to do with ts-node and that its actually calling require under the hood.
Suffice to say, im wondering if there is a way to import this package and use it together with oclif short of changing the package to use commonjs (which i hesitate to do).
Issue Analytics
- State:
- Created 2 years ago
- Reactions:22
- Comments:5
Top Results From Across the Web
Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
However I keep getting this message: [ERR_REQUIRE_ESM]: require() of ES Module from not supported. Instead change the require of index. js in... ...
Read more >Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
The error [ERR_REQUIRE_ESM]: require() of ES Module not supported. Instead change the require of index.js to a dynamic import() which is available in...
Read more >require() of es module is not supported - You.com - You.com
The main problem is that the CommonJS build tries to require the ESM-only module is-plain-obj . This is never going to work. A...
Read more >JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax. A background on modules. JavaScript programs started off pretty ......
Read more >Content Types - ESBuild
#The default export can be error-prone ... The ES module format (i.e. ESM) have a special export called default that sometimes behaves differently...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If globby is updated to 13 then oclif cannot find any commands at all 😱
Potentially Related: