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

ERR_REQUIRE_ESM failure when using unist-util-visit>=3.0.0 #18

Closed
candrews opened this issue Nov 29, 2021 · 2 comments · Fixed by #19
Closed

ERR_REQUIRE_ESM failure when using unist-util-visit>=3.0.0 #18

candrews opened this issue Nov 29, 2021 · 2 comments · Fixed by #19
Milestone

Comments

@candrews
Copy link
Contributor

candrews commented Nov 29, 2021

Describe the bug
As of unist-util-visit version 3.0.0, ESM must be used.

When using mdx-mermaid version 1.1.1 (the current latest release) with unist-util-visit version 4.1.0 (the current latest release), the build fails with ERR_REQUIRE_ESM

To Reproduce
Set up a simple docusaurus project with mdx-mermaid, then run docusaurus build

Expected behavior
Build should succeed.

Screenshots
n/a

Stack trace

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/candrews/projects/docs/node_modules/unist-util-visit/index.js from /home/candrews/projects/docs/node_modules/mdx-mermaid/lib/mdxast-mermaid.js not supported.
Instead change the require of index.js in /home/candrews/projects/docs/node_modules/mdx-mermaid/lib/mdxast-mermaid.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/candrews/projects/docs/node_modules/mdx-mermaid/lib/mdxast-mermaid.js:20:44)
    at Object.<anonymous> (/home/candrews/projects/docs/docusaurus.config.js:81:15)
    at module.exports (/home/candrews/projects/docs/node_modules/import-fresh/index.js:32:59)
    at loadConfig (/home/candrews/projects/docs/node_modules/@docusaurus/core/lib/server/config.js:17:53)
    at loadSiteConfig (/home/candrews/projects/docs/node_modules/@docusaurus/core/lib/server/index.js:33:51)
    at loadContext (/home/candrews/projects/docs/node_modules/@docusaurus/core/lib/server/index.js:43:69)
    at build (/home/candrews/projects/docs/node_modules/@docusaurus/core/lib/commands/build.js:48:52)
    at Command.<anonymous> (/home/candrews/projects/docs/node_modules/@docusaurus/core/bin/docusaurus.js:54:5)
    at Command.listener [as _actionHandler] (/home/candrews/projects/docs/node_modules/@docusaurus/core/node_modules/commander/index.js:413:31)
    at Command._parseCommand (/home/candrews/projects/docs/node_modules/@docusaurus/core/node_modules/commander/index.js:914:14)
    at Command._dispatchSubcommand (/home/candrews/projects/docs/node_modules/@docusaurus/core/node_modules/commander/index.js:865:18)
    at Command._parseCommand (/home/candrews/projects/docs/node_modules/@docusaurus/core/node_modules/commander/index.js:882:12)
    at Command.parse (/home/candrews/projects/docs/node_modules/@docusaurus/core/node_modules/commander/index.js:717:10)
    at run (/home/candrews/projects/docs/node_modules/@docusaurus/core/bin/docusaurus.js:244:7)
    at Object.<anonymous> (/home/candrews/projects/docs/node_modules/@docusaurus/core/bin/docusaurus.js:251:1)

Tool chain used:
npm 8.0.0, node v16.11.1

Additional context

candrews added a commit to candrews/mdx-mermaid that referenced this issue Dec 2, 2021
sjwall added a commit that referenced this issue Jan 8, 2022
* Set up spys instead of using mock

jest.mock doesn't work work against ES6 modules, but this approach of
using spys instead does.

See: jestjs/jest#10025

* Export as an ES6 module instead of CommonJS

* Upgrade unist-util-visit to 3.0.0

* Upgrade unist-util-visit to 4.1.0

Closes: #18

* Use `import` instead of `require`

* Use ES2020 instead of ESNext

It's best to use a specific version to ensure a consistent, reproducible
product.

Co-authored-by: Sam Wall <oss@samuelwall.co.uk>
@sjwall sjwall added this to the v2.0.0 milestone Jan 8, 2022
@willin
Copy link

willin commented Jan 30, 2022

perhaps a same issue:


/Users/v0/Sites/willin.wang/scripts/node_modules/mermaid/dist/mermaid.core.js:30092
module.exports = require("d3");
                 ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/v0/Sites/willin.wang/scripts/node_modules/d3/src/index.js from /Users/v0/Sites/willin.wang/scripts/node_modules/mermaid/dist/mermaid.core.js not supported.
Instead change the require of index.js in /Users/v0/Sites/willin.wang/scripts/node_modules/mermaid/dist/mermaid.core.js to a dynamic import() which is available in all CommonJS modules.
    at Object.d3 (/Users/v0/Sites/willin.wang/scripts/node_modules/mermaid/dist/mermaid.core.js:30092:18)
    at __webpack_require__ (/Users/v0/Sites/willin.wang/scripts/node_modules/mermaid/dist/mermaid.core.js:30325:41)
    at Object../src/mermaidAPI.js (/Users/v0/Sites/willin.wang/scripts/node_modules/mermaid/dist/mermaid.core.js:26042:60)
    at __webpack_require__ (/Users/v0/Sites/willin.wang/scripts/node_modules/mermaid/dist/mermaid.core.js:30325:41)
    at Object../src/mermaid.js (/Users/v0/Sites/willin.wang/scripts/node_modules/mermaid/dist/mermaid.core.js:25828:69)
    at __webpack_require__ (/Users/v0/Sites/willin.wang/scripts/node_modules/mermaid/dist/mermaid.core.js:30325:41)
    at /Users/v0/Sites/willin.wang/scripts/node_modules/mermaid/dist/mermaid.core.js:30392:37
    at /Users/v0/Sites/willin.wang/scripts/node_modules/mermaid/dist/mermaid.core.js:30396:12
    at webpackUniversalModuleDefinition (/Users/v0/Sites/willin.wang/scripts/node_modules/mermaid/dist/mermaid.core.js:3:20)
    at Object.<anonymous> (/Users/v0/Sites/willin.wang/scripts/node_modules/mermaid/dist/mermaid.core.js:10:3)
    at Object.<anonymous> (/Users/v0/Sites/willin.wang/scripts/node_modules/mdx-mermaid/lib/Mermaid.js:44:33)
    at Object.<anonymous> (/Users/v0/Sites/willin.wang/scripts/mdx.js:12:21)
    at Object.<anonymous> (/Users/v0/Sites/willin.wang/scripts/index.js:4:25) {
  code: 'ERR_REQUIRE_ESM'
}

@sjwall
Copy link
Owner

sjwall commented Aug 10, 2022

This is resolved with release v2.0.0-rc1. I'll promote to v2.0.0 in a week or so if there are no bugs reported

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

Successfully merging a pull request may close this issue.

3 participants