-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[charts][ESM] Can't import @mui/x-charts under node.js #11016
Comments
Also having the exact same problem atm while working on a Remix based project. |
The issue is broader to MUI in general. It's not so pretty https://stackblitz.com/edit/stackblitz-starters-qxwznw?file=index.mjs. |
👍 This is a long standing issue. More context in the following:
We're just starting on an effort with @DiegoAndai and @mui/code-infra to try and solve it for v6. End goal is to remove all commonjs from the package and have it load esm files both in node.js and in bundlers. Eventually being ESM only and eliminating all the dual loading issues. |
@Janpot I guess where @mui/x-charts is different is that there is no way to import under node.js ESM. I assume it's because it uses the Anyway, fixing this sounds great. People before us tried https://blog.isquaredsoftware.com/2023/08/esm-modernization-lessons/, I would hope the ecosystem is in a better shape to make it work. |
Yep, that;s roughly it. The |
I urgently need to use @mui/x-charts in my Remix+Vite project. |
@vimutti77 Can you provide a minimal reproduction for your setup? |
Here is the repo: https://github.com/vimutti77/remix-vite-mui Steps
|
I'm not sure if this will be helpful, but Lexical also encountered a similar issue with ESM. But for now, I'm using const BarChart = lazy(() => import('@mui/x-charts').then((x) => ({ default: x.BarChart })))
<Suspense>
<BarChart .../>
</Suspense> |
Thank you. For now you can fix it by transpiling // vite.config.ts
// ...
ssr: {
noExternal: ["@mui/utils", "@mui/x-charts"],
},
// ... => In core, for v7, we're at the moment working on making the packages compatible with Node.js ESM loader. Once that work is complete we'll port the method to X and this should make all X packages runnable under Node.js as well. In the meantime you can fall back to transpiling the packages on Node.js. |
when trying this - it 'resolves' the initial error but then i see the following: Application Error |
Hi! Any progress on this? Is there any way I can use x-charts for with my nodejs setup? Using the latest nodejs and are getting the error as stated in issue. Appreciate all the answers and help I can get. This is the last piece of a puzzle I've been working on for 9 years 😃 |
Steps to reproduce
Link to live example: https://stackblitz.com/edit/stackblitz-starters-6fdpqg?file=index.mjs
Steps:
node index.mjs
Current behavior
Error:
Expected behavior
The module can be imported under Node.js
Context
See mui/toolpad#2915
In Toopad we import our components under node.js to read out its configuration and generate documentation. Failing build: https://app.circleci.com/pipelines/github/mui/mui-toolpad/11238/workflows/9bd45ad4-e0d1-40d4-b4b8-c22e44035107/jobs/49528. The
@mui/x-charts
package is not spec compliant. To make it so we'll need to:Your environment
npx @mui/envinfo
Search keywords: import charts node.js esm
The text was updated successfully, but these errors were encountered: