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

The requested module moment does not provide an export named default #33

Closed
luckylooke opened this issue Jan 24, 2023 · 17 comments · Fixed by mermaid-js/mermaid#4034 or mermaid-js/mermaid#4153

Comments

@luckylooke
Copy link

Hi,
after installation into my project I am getting error in browser console, running vitepress docs:

Uncaught SyntaxError: The requested module '...somepath.../node_modules/moment-mini/moment.min.js?v=fabf3af1' does not provide an export named 'default' (at mermaid.core.mjs?v=fabf3af1:7:8)

I have already tried to setup my tsconfig.json, adding

  "compilerOptions": {
    "module": "es6",
    "esModuleInterop": true,
    "moduleResolution": "node",
    "allowJs": true
  },

but didn't fixed... any idea what to try?

Many thanks 🙏

@luckylooke
Copy link
Author

I have created minimal reproduction here: https://stackblitz.com/edit/github-zbjrsg-zc4yzq?file=package.json thanks 🙏😊

@towerhe
Copy link

towerhe commented Jan 25, 2023

@luckylooke try to use "mermaid": "9.1.7" instead of the latest version "9.3.0"

@daniilguit
Copy link

@towerhe - this does indeed help, thanx.

@emersonbottero
Copy link
Owner

It should work in the last version.
I can duplicate the issue and asked for help from mermaid developers.

@emersonbottero
Copy link
Owner

And it only throw erros in dev.
So. If you need mind map you can use it in build and it should work.

@lukastaegert
Copy link

While not ideal, I managed to work around this issue by adding a vite.config.js with

optimizeDeps: { include: ['moment-mini', '@braintree/sanitize-url'] }

as apparently, the CommonJS detection did not work correctly for those dependencies.

@wuleninja
Copy link

Hi! I get the same issue with module dayjs right after the install (done today):

Uncaught SyntaxError: The requested module '/node_modules/dayjs/dayjs.min.js?v=d4754311' does not provide an export named 'default' (at mermaid-ae477ddf.js?v=d4754311:2:8)

Does someone knows a workaround?

@wuleninja
Copy link

Ok, setting "mermaid": "9.1.7" did the trick for me

@a2k42
Copy link

a2k42 commented Mar 19, 2023

Slightly different error in console Uncaught SyntaxError: ambiguous indirect export: default but same solution.

When I check to see the source of the problem it is dayjs in the latest version of mermaid 10.0.2? It was coming from moment-mini when I had an earlier version installed.

@emersonbottero
Copy link
Owner

the solution above should work for vitepress v10.0.0 as long as your chart don't use dates..

the final solution should wait for the dayjs 2.0 to have an official release.. see mermaid-js/mermaid#4153 (comment)

@emersonbottero
Copy link
Owner

Another change I made that should fix this..
mermaid-js/mermaid#4285
Need to wait for next release to test it.

@paschembri
Copy link

paschembri commented Jun 19, 2023

For those wondering how to make it work for a fresh install:

The required changes are:

  1. .vitepress/config.ts
  2. package.json

In .vitepress/config.ts

import { defineConfig } from 'vitepress'
import { withMermaid } from "vitepress-plugin-mermaid";

export default withMermaid(
  defineConfig({
    vite: {
      optimizeDeps: { include: ['@braintree/sanitize-url'] },
      resolve: {
          alias: {
            dayjs: 'dayjs/',
          },
        },
    },
...

In package.json devDependencies make sure to have

    "@mermaid-js/mermaid-mindmap": "^9.3.0",
    "mermaid": "^8.14.0",

With the previous modifications I could have both dev and build targets

@dspinov
Copy link

dspinov commented Jul 17, 2023

Another change I made that should fix this.. mermaid-js/mermaid#4285 Need to wait for next release to test it.

It still is not working, and I see that PR was reverted by the mermaid team on June 1. At the same time, I see in the last commits that the plugin updated deps on mermaid 10. Any ideas on how to make it work? I don't have charts with dates but I can't build my docs with error: "dayjs/dayjs.min.js?v=8dd7652e' does not provide an export named 'default' "

@emersonbottero
Copy link
Owner

@dspinov It should be working.. but I just discovered it is not pnpm compatible..
can you check using npm?

@dspinov
Copy link

dspinov commented Oct 2, 2023

Hi @emersonbottero. You are right. I've tested with npm and all is good. This is interesting. I didn't find any related issues about that. I see that dayjs team has mentioned a solution for the same problem by using esModuleInterop in TS. But I don't have TS on the project. Do you know maybe how to do the same with vitejs only?

@emersonbottero
Copy link
Owner

I added all necessary settings on the package, you can try pnpm install --shamefully-hoist .

What make it to work was this changes

@FliPPeDround
Copy link

FliPPeDround commented Oct 10, 2023

I added all necessary settings on the package, you can try pnpm install --shamefully-hoist .

What make it to work was this changes

There is a new issue when using 'pnpm install --shamefully-hoist' with the 'mermaid' module.

The requested module '/node_modules/.pnpm/[email protected]/node_modules/mermaid/dist/mermaid.core.mjs?v=6f627caa' does not provide an export named 'ExternalDiagramDefinition'

"mermaid": "10.5.0",
"vitepress": "1.0.0-rc.20",
"vitepress-plugin-mermaid": "2.0.15"

I'm uncertain about the solution to this problem. Could you please provide some suggestions?

thanks💕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
10 participants