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

Next JS 13.4 appDir - MUI Compiled /page in 8.2s (2728 modules) #39432

Open
imceZZ opened this issue Oct 14, 2023 · 4 comments
Open

Next JS 13.4 appDir - MUI Compiled /page in 8.2s (2728 modules) #39432

imceZZ opened this issue Oct 14, 2023 · 4 comments
Assignees
Labels

Comments

@imceZZ
Copy link

imceZZ commented Oct 14, 2023

I am using "@mui/material": "5.14.13" and "next": "13.5.4" but during development and also build is slow I saw another topic that was discussing this issue but I couldn't find any answer that will work I also tried flatten import example from this:

import { Box } from "@mui/material";

to this:

import Box from "@mui/material/Box";

this reduces first load js but again its not how it should be, again it loads 2728 modules.

this is screenshot when I run yarn dev:

N37xD

this is documentation that I followed to implement MUI in next js: MUI DOC

please don't close this until it has solution this is headache.

@github-actions github-actions bot added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 14, 2023
@imceZZ imceZZ changed the title Next JS 13.4 appDir - MUI Compiled /page in 8.2s (2731 modules) Next JS 13.4 appDir - MUI Compiled /page in 8.2s (2728 modules) Oct 15, 2023
@zannager zannager added package: system Specific to @mui/system component: Box The React component. and removed package: system Specific to @mui/system labels Oct 16, 2023
@imceZZ
Copy link
Author

imceZZ commented Nov 8, 2023

@siriwatknp any update for this issue.

@mnajdova
Copy link
Member

mnajdova commented Nov 8, 2023

Are you using the modularizeImports option? We need a reproduction repository so that we can investigate what is the problem. Without it we cannot act on anything.

@mnajdova mnajdova added status: waiting for author Issue with insufficient information nextjs and removed component: Box The React component. status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 8, 2023
@imceZZ
Copy link
Author

imceZZ commented Nov 10, 2023

@mnajdova you can replicate this problem by just creating pure Next Js project and try to implement MUI app dir structure following this

Also the same problem encountering many users:

Vercel discussion
another topic for same problem

I have tried modularizeImports but again its not how it should be.

modularizeImports: {
        "@mui/material/?(((\\w*)?/?)*)": {
            transform: "@mui/material/{{ matches.[1] }}/{{member}}",
            skipDefaultConversion: true,
        },
    },

Also Next JS has introduced optimizePackageImports but again it has problems LINK

This is a screenshot from Webpack Bundle Analyzer:

Screenshot 2023-11-10 at 12 56 45

As I know MUI uses tree-shaking (Tree-shaking Material UI works out of the box in modern frameworks. )

Is this problem from barrel index file's or not. What we can do to resolve this issue I think this issue should have priority on MUI as Next JS is very popular framework.

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label Nov 10, 2023
@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 16, 2024

This looks like a duplicate of #35840 to me.

I don't see much to do about it, barrel indexes are slow: https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7/. And maybe Next.js made it faster in https://vercel.com/blog/how-we-optimized-package-imports-in-next-js:

SCR-20240216-cpmd

but Vite, etc. didn't.

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

No branches or pull requests

5 participants