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

Requiring from CommonJS is broken #2559

Closed
sdegutis opened this issue Dec 14, 2021 · 8 comments
Closed

Requiring from CommonJS is broken #2559

sdegutis opened this issue Dec 14, 2021 · 8 comments
Assignees
Labels
Type: Bug / Error Something isn't working or is incorrect

Comments

@sdegutis
Copy link

Describe the bug
To Reproduce
Expected behavior
Code Sample

When you install this from a Node app and require('mermaid'), it fails with this error:

module.exports = require("d3");
                 ^

Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules\d3\src\index.js
  from node_modules\mermaid\dist\mermaid.core.js not supported.
Instead change the require of index.js in node_modules\mermaid\dist\mermaid.core.js
  to a dynamic import() which is available in all CommonJS modules.

Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context

n/a

@sdegutis sdegutis added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels Dec 14, 2021
@sidharthv96
Copy link
Member

This might have been fixed in 8.13.3
Ref: #2677 (comment)

@sidharthv96 sidharthv96 added Status: Awaiting Reply and removed Status: Triage Needs to be verified, categorized, etc labels Feb 3, 2022
@sidharthv96 sidharthv96 self-assigned this Feb 3, 2022
@kilgarenone
Copy link

I'm facing this issue in 8.14.0

Eleventy:EleventyErrorHandler     at internal/main/run_main_module.js:17:47 +0ms
[11ty] Must use import to load ES Module: /mnt/c/Users/kwei8/knowledge-base1/node_modules/d3/src/index.js
require() of ES modules is not supported.
require() of /mnt/c/Users/kwei8/knowledge-base1/node_modules/d3/src/index.js from /mnt/c/Users/kwei8/knowledge-base1/node_modules/mermaid/dist/mermaid.core.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 index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /mnt/c/Users/kwei8/knowledge-base1/node_modules/d3/package.json.

@sidharthv96
Copy link
Member

@kilgarenone can you share a repro?

@kilgarenone
Copy link

@sidharthv96
Copy link
Member

https://github.com/mermaid-js/mermaid-live-editor/blob/278982c2465c9197114b9f49e2340c23d3f26684/src/lib/components/view.svelte#L6

Can you check this project and use the build settings we use there?
Your issue might be solved by that.

@kilgarenone
Copy link

kilgarenone commented Feb 18, 2022

I believe that works because it imports the esm version of mermaid.

Issue at hand arises when we const Mermaid = require('mermaid').

EDIT: I believe there's nothing can be done on mermaid side coz d3 only output ESM of their lib...unlike mermaid - both .cjs and esm.

@alexn-s
Copy link

alexn-s commented May 7, 2022

@kilgarenone sadly your link can no longer be found. Does the repo still exist?

@jgreywolf
Copy link
Contributor

The simple answer is that we will not be supporting "require" from cjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

No branches or pull requests

5 participants