question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: require of ES Module x from y is not supported

See original GitHub issue

Greetings,

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:open
  • Created 2 years ago
  • Reactions:22
  • Comments:5

github_iconTop GitHub Comments

5reactions
crucialfelixcommented, May 2, 2022

If globby is updated to 13 then oclif cannot find any commands at all 😱

(base) (⎈ |N/A:N/A) % ./bin/dev whoami                                                                                                                              github/sensilla-cli (main ⚡) Chriss-MacBook-Pro
(node:84017) [ERR_REQUIRE_ESM] Error Plugin: sensilla-cli [ERR_REQUIRE_ESM]: require() of ES Module /Users/crucialfelix/github/sensilla-cli/node_modules/globby/index.js from /Users/crucialfelix/github/sensilla-cli/node_modules/@oclif/core/lib/config/plugin.js not supported.
Instead change the require of index.js in /Users/crucialfelix/github/sensilla-cli/node_modules/@oclif/core/lib/config/plugin.js to a dynamic import() which is available in all CommonJS modules.
module: @oclif/core@1.7.0
task: not loading commands, globby not found
// Pin it to 11 and it works again:
    "globby": "^11",
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found