-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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] Doesn't build in Next.js due to require() of ES Module (ERR_REQUIRE_ESM) #9826
Comments
@alexfauquette This might be coming from the |
Yes, but the "exports": {
".": {
"require": "./index.js",
"import": "./esm/index.js"
},
"./*": {
"require": "./*",
"import": "./esm/*"
}
}, |
For now, I've dealt with this by adding it to next.config.js /** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: true,
transpilePackages: ['@mui/x-charts'],
}; |
Did you also had to transpile the |
No (at least I did not need to include them in the list). I'm unsure on whether it's done for dependencies automatically or not. |
Updated to import { PieChart } from "@mui/x-charts"; I get
. Adding modularizeImports: {
"@mui/material": {
transform: "@mui/material/{{member}}"
},
...
"@mui/x-charts": {
transform: "@mui/x-charts/{{member}}"
}
}, Gives me the same error but with a bunch of
So for now, I'm leaving charts in |
I faced the same problem with Next.js's Material UI starter example (the most used one).
#9826 (comment) 's workaround did the trick. But this shouldn't be needed to make it work. |
@oliviertassinari What version of Next were you using? |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Current behavior export * from './PieChart'; Fixed with
Then open your next.config.js file and add the following lines:
|
@MonstraG: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
The fix will be available in the next release at the end of the week |
Steps to reproduce 🕹
Link to live example: https://codesandbox.io/p/sandbox/vibrant-tharp-7ktt9w
Current behavior 😯
Server Error:
Error: require() of ES Module /project/home/monstrag/workspace/node_modules/d3-scale/src/index.js from /project/home/monstrag/workspace/node_modules/@mui/x-charts/context/CartesianContextProvider.js not supported.
Instead change the require of index.js in /project/home/monstrag/workspace/node_modules/@mui/x-charts/context/CartesianContextProvider.js to a dynamic import() which is available in all CommonJS modules.
Stacktrace
Expected behavior 🤔
Runs
Context 🔦
Seems to be a bug with Next.js: vercel/next.js#39375.
Your environment 🌎
npx @mui/envinfo
Order ID or Support key 💳 (optional)
No response
The text was updated successfully, but these errors were encountered: