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

@mui/icons-material breaks Next.js Serverless Function and gives timed out error when adding any icon at _app.tsx page #35450

Closed
2 tasks done
dev-ahmedhany opened this issue Dec 12, 2022 · 8 comments · Fixed by vercel/next.js#51953
Labels
enhancement This is not a bug, nor a new feature nextjs package: icons Specific to @mui/icons performance

Comments

@dev-ahmedhany
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example:

https://github.com/dev-ahmedhany/nextjs-mui-bug

Steps:

1.get nextjs starter template
2.add icon from @mui/icons-material to _app.tsx

Current behavior 😯

Serverless Function has timed out

Expected behavior 🤔

Serverless Function to work

Context 🔦

It made me use material design icons instead of @mui/icons-material

Your environment 🌎

npx @mui/envinfo

the problem only at web , It works at localhost

System:
    OS: macOS 13.0.1
  Binaries:
    Node: 16.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.15.0 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 108.0.5359.98
    Edge: Not Found
    Firefox: 102.0.1
    Safari: 16.1
  npmPackages:
    @emotion/react: ^11.10.5 => 11.10.5 
    @emotion/styled: ^11.10.5 => 11.10.5 
    @mui/base:  5.0.0-alpha.109 
    @mui/core-downloads-tracker:  5.10.17 
    @mui/icons-material: ^5.10.16 => 5.10.16 
    @mui/material: ^5.10.17 => 5.10.17 
    @mui/private-theming:  5.10.16 
    @mui/styled-engine:  5.10.16 
    @mui/system:  5.10.17 
    @mui/types:  7.2.2 
    @mui/utils:  5.10.16 
    @types/react: 18.0.26 => 18.0.26 
    react: 18.2.0 => 18.2.0 
    react-dom: 18.2.0 => 18.2.0 
    typescript: 4.9.4 => 4.9.4 
@dev-ahmedhany dev-ahmedhany added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 12, 2022
@zannager zannager added the package: icons Specific to @mui/icons label Dec 12, 2022
@michaldudak
Copy link
Member

Try importing just the icon you need instead of the whole package: https://mui.com/material-ui/guides/minimizing-bundle-size/#option-one-use-path-imports

-import { Person } from "@mui/icons-material";
+import Person from "@mui/icons-material/Person";

@michaldudak michaldudak removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 12, 2022
@dev-ahmedhany
Copy link
Author

dev-ahmedhany commented Dec 12, 2022

worked!! Thanks

also searched and found a better Developer experience solution:
using modularizeImports works well without having to fallback to babel.
this makes the building process faster at Vercel servers

const nextConfig = {
  reactStrictMode: true,
  experimental: {
    modularizeImports: {
      "@mui/material": {
        transform: "@mui/material/{{member}}",
      },
      "@mui/icons-material": {
        transform: "@mui/icons-material/{{member}}",
      },
    },
  },
};

I think this needs to be added to the docs

@dev-ahmedhany
Copy link
Author

Can't we copy the material design icons importing system?
this bug isn't there although they have more icons

@michaldudak
Copy link
Member

I think this needs to be added to the docs

Would you like to open a PR?

Can't we copy the material design icons importing system?
this bug isn't there although they have more icons

We are going to overhaul the packaging of all our libraries in v6 (and create proper ES modules).

dev-ahmedhany added a commit to dev-ahmedhany/material-ui that referenced this issue Dec 13, 2022
mui#35450



Signed-off-by: Ahmed Hany <39633124+dev-ahmedhany@users.noreply.github.com>
@dev-ahmedhany
Copy link
Author

done can you review it ? @michaldudak

@oliviertassinari
Copy link
Member

Next.js did a PR to solve this problem directly with a default configuration: vercel/next.js#50900.

ijjk added a commit to vercel/next.js that referenced this issue Jun 29, 2023
Fixes #51872. We were exploring in
mui/material-ui#35457 the option to move the
`modularizeImports` config to our Next.js examples to fix
mui/material-ui#35450 however, we never got to
complete the work.

We are not yet in a position where we can apply modularizeImports to
`@mui/material`. We still have folders to create to make it work.

Maybe we should close mui/material-ui#35457?

Co-authored-by: JJ Kasper <jj@jjsweb.site>
@oliviertassinari oliviertassinari changed the title @mui/icons-material breaks nextjs Serverless Function and gives timed out error when adding any icon at _app.tsx page @mui/icons-material breaks Next.js Serverless Function and gives timed out error when adding any icon at _app.tsx page Jul 24, 2023
kubagp1 added a commit to kubagp1/school-clock that referenced this issue Aug 5, 2023
@michaldudak
Copy link
Member

@dev-ahmedhany does this problem still exist with the PR Olivier mentioned?

Jiganesh added a commit to Jiganesh/chess-stat-card that referenced this issue Oct 14, 2023
@zannager zannager added the nextjs label Jan 3, 2024
@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 18, 2024

Closing per #35450 (comment). Problem solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is not a bug, nor a new feature nextjs package: icons Specific to @mui/icons performance
Projects
None yet
4 participants