-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
v14.2 causing build error for Material UI Icons #64518
Comments
I'm having this issue as well! |
This should Not be closed... I have the Exact same issue using the newest version 14.2.1-canary.7 Running in Dev works fine but when I build and then next start i get:
also using MUI Material and Icons. Everything worked fine before next 14.2 Bonus: After the newest update I keep running out of memory too: `> next build ▲ Next.js 14.2.1
Creating an optimized production build ... Never seen this issue before... But it keeps happening. To fix it I delete the .next folder and then I can build again... |
Change how you import material ui package from this: To this: Originally posted by @Tosinkoa in #63394 (comment) |
I'm having the same error on another package, "react-fast-marquee". The error happens during runtime if the page is marked with It seems it's importing the package as I prepared a minimal reproduction codesandbox here |
@filmic thanks that works, however, for large projects this workaround might be very tedious to do since requires a big refactor. |
Found another related issue, in the Only works if changes from I think this has to do with @ibobo mentioned in this comment #64518 (comment) |
I identify the issue is related to CJS dependency, preparing a fix in #64558 . If you're using Prefer import { Abc } from "@mui/icons-material" rather than import Abc from "@mui/icons-material/Abc" The reason is that the direct subpath import |
## What Determine if the client module is a CJS file and `default` export is imported, then we include the whole module instead of using webpack magic comments to only extract `default` export. ## Why Unlike ESM, The `default` export of CJS module is not just `.default` property, we need to include `__esModule` mark along with `default` export to make it function properly with React client module proxy Fixes #64518 Closes NEXT-3119
Yes, you're right. To avoid making it tedious, you can do And lastly for same file, you can do |
Landed the fix on canary, please upgrade to v14.3.0-canary.5! 🙏 |
Testing on 14.3.0-canary.5 I am still having the same issue. Changing all MUI imports, not just icons, was the only fix, (and this is bad practice for MUI). Any thing I need to do to allow importing default without this error? |
@justinh00k same |
I confirm that my problem is fixed on 14.3.0-canary.5 (thanks!), but it seems @lucasvieirasilva's one is not. |
Taking another round of look for this case of material lib |
This worked for me. Spend about 2 hours changing god knows how many imports, but it actually fixed the issue using 14.3.0-canary.5. I also changed my Next/dynamic to React.Lazy witch solved an error using edge runtime, but I can see there is allready a pr for that. |
## What Determine if the client module is a CJS file and `default` export is imported, then we include the whole module instead of using webpack magic comments to only extract `default` export. ## Why Unlike ESM, The `default` export of CJS module is not just `.default` property, we need to include `__esModule` mark along with `default` export to make it function properly with React client module proxy Fixes #64518 Closes NEXT-3119
### Why If you have a client entry that mixing `default` re-export and `*` re-export, atm we cannot statically analyze all the exports from this the boundary, unless we can apply barrel file optimization for every import which could slow down speed. ```js // index.js 'use client' export * from './client' export { default } from './client' ``` Before that happen we high recommend you don't mixing that and try to add the client directive to the leaf level client module. We're not able to determine what the identifiers are imported from the wildcard import path. This would work if we resolved the actual file but currently we can't. ### What When we found the mixing client entry module like that, we treat it as a CJS client module and include all the bundle in client like before what we have the client components import optimization. Ideally we could warn users don't apply the client directive to these kinda of barrel file, and only apply them to where we needed. Fixes #64518 Closes NEXT-3119
I got a fix up in #64681 and landed, but there's still sth need to be changed on mui side to let users get better optimization of client code. This change is landed in 14.3.0-canary.9 The case of |
Can confirm this issue was fixed on my end after updating from For reference, my issue was simply using a MUI element on my main page providing the same error as the initial issue. |
|
To clarify about the fixes: The mui icon related fix, which initially mentioned in the issue description, is fixed in 14.2.2. |
@AbdullahElrubi can you provide a reproduction using next.js canary? |
Latest canary fixed all of my issues without changing a single import path (all of my paths were default-style and 14.2.2 upgrade was not enough). |
@huozhi the latest canary fixed the issue for me |
### Why If you have a client entry that mixing `default` re-export and `*` re-export, atm we cannot statically analyze all the exports from this the boundary, unless we can apply barrel file optimization for every import which could slow down speed. ```js // index.js 'use client' export * from './client' export { default } from './client' ``` Before that happen we high recommend you don't mixing that and try to add the client directive to the leaf level client module. We're not able to determine what the identifiers are imported from the wildcard import path. This would work if we resolved the actual file but currently we can't. ### What When we found the mixing client entry module like that, we treat it as a CJS client module and include all the bundle in client like before what we have the client components import optimization. Ideally we could warn users don't apply the client directive to these kinda of barrel file, and only apply them to where we needed. Fixes #64518 Closes NEXT-3119
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
https://github.com/lucasvieirasilva/nextjs-mui-issue1
To Reproduce
npm install
npm run build
Current vs. Expected behavior
Currently, when there's any MUI Icon in the page the build command throws the following exception:
I've also tested only the MUI component (e.g. Grid) and the build works correctly, it only fails with MUI Icons (
@mui/icons-material
)If the static pages don't have any MUI Icon and any dynamic route page has MUI Icons the build works fine, but the page crashes when you try to access the application.
Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
I've tested with the new
v14.2.1-canary.5
version which is supposed to fix this issue, but apparently, it only fixes MUI components, not MUI icons.Issue reference: #64369
I've tested with Next.js
14.1.4
and works fine.The
14.2.1-canary.7
and14.3.0-canary.0
versions are not working as well.NEXT-3119
The text was updated successfully, but these errors were encountered: