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.

[ERR_REQUIRE_ESM]: require() of ES Module

See original GitHub issue

Hey, it’s me again. I tried to write an SEO library for rakkas and I found that I could migrate next-seo over, so I modified the bundle way of next-seo library and released a version. But I ran into some problems and got an error in SSR. error [ERR_REQUIRE_ESM]: require() of ES Module, in CSR ta is working.

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/innei/git/demo/rakkasjs-demo/node_modules/.pnpm/rakkasjs@0.6.0_yogrrpwgdz2zmfozuavyhqdpum/node_modules/rakkasjs/dist/server.js from /Users/innei/git/demo/rakkasjs-demo/node_modules/.pnpm/rakkas-seo@0.6.0-4_rakkasjs@0.6.0/node_modules/rakkas-seo/lib/meta/defaultSEO.js not supported.
Instead change the require of server.js in /Users/innei/git/demo/rakkasjs-demo/node_modules/.pnpm/rakkas-seo@0.6.0-4_rakkasjs@0.6.0/node_modules/rakkas-seo/lib/meta/defaultSEO.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/innei/git/demo/rakkasjs-demo/node_modules/.pnpm/rakkas-seo@0.6.0-4_rakkasjs@0.6.0/node_modules/rakkas-seo/lib/meta/defaultSEO.js:29:20)
    at Object.<anonymous> (/Users/innei/git/demo/rakkasjs-demo/node_modules/.pnpm/rakkas-seo@0.6.0-4_rakkasjs@0.6.0/node_modules/rakkas-seo/lib/index.js:7:20)
    at async Promise.all (index 0)
    at async nodeImport (file:///Users/innei/git/demo/rakkasjs-demo/node_modules/.pnpm/vite@3.0.9/node_modules/vite/dist/node/chunks/dep-0fc8e132.js:50619:21)
    at async eval (/src/routes/index.page.tsx:10:31)
    at async instantiateModule (file:///Users/innei/git/demo/rakkasjs-demo/node_modules/.pnpm/vite@3.0.9/node_modules/vite/dist/node/chunks/dep-0fc8e132.js:50548:9) {
  code: 'ERR_REQUIRE_ESM'
}

My repo is here. https://github.com/Innei/rakkas-seo.

The library entry I wrote as:

// package.json
"main": "lib/index.js", // cjs
  "module": "esm/index.js", // esm
  "unpkg": "lib/index.js",
  "types": "types/index.d.ts",

3Q

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Inneicommented, Sep 4, 2022

Thanks, solve my issue.

1reaction
cyco130commented, Sep 4, 2022

Oh, got it. You’re using Rakkas from your own lib. Then you’ll have to add ssr: noExternal: ["mylib"] to your vite.config. Rakkas is a “special” library that has to be processed by Vite. If you’re using it from your own lib, then your lib has to be processed by it too. That’s what noExternal does.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
The node-fetch latest version doesn't use the require() syntax to import the package. You need to go to your package.json and type
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 >
Must use import to load ES Module / require() of ES ... - GitHub
I have suddenly started getting the following error: $ npm test > geodesy@2.2.0 test /home/travis/build/chrisveness/geodesy > mocha --exit ...
Read more >
Error [ERR_REQUIRE_ESM]: require() of ES Module - Support
Error [ERR_REQUIRE_ESM]: require() of ES Module when trying to compile a typescript service implementing the netlify api module. Version 11.0.1.
Read more >
ERR_REQUIRE_ESM - DEV Community ‍ ‍
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: ~/projects/semantic-release-toolkit/node_modules/zz/cjs.js require() of ES ...
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