Skip to content

Cannot import @mui/material from an ESM dependency #78116

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

Open
bartlangelaan opened this issue Apr 13, 2025 · 2 comments
Open

Cannot import @mui/material from an ESM dependency #78116

bartlangelaan opened this issue Apr 13, 2025 · 2 comments
Labels
Module Resolution Module resolution (CJS / ESM, module resolving). Webpack Related to Webpack with Next.js.

Comments

@bartlangelaan
Copy link
Contributor

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/nextjs-issue-cannot-import-mui-material-from-mjs-dependency-88x7qr

To Reproduce

  1. Run pnpm install
  2. Run pnpm run build in the packages/example-alert folder
  3. Start the application (root folder) in development (pnpm run dev)

Current vs. Expected behavior

The following error appears: Error: Element type is invalid. Received a promise that resolves to: [object Module]. Lazy element type must resolve to a class or function.

This happens in both the app router and the pages router, if a dependency renders something from @mui/material.

It does work with Turbopack, but not with Webpack.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4242
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.3.1-canary.7 // Latest available version is detected (15.3.1-canary.7).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Module Resolution, Webpack

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local)

Additional context

The package is compiled to this:

// src/index.tsx
import { Alert } from "@mui/material";
import { jsx } from "react/jsx-runtime";
function ExampleAlert() {
  return /* @__PURE__ */ jsx(Alert, { children: "This is a simple alert!" });
}
export {
  ExampleAlert
};

The Alert import is not resolved to a component somehow while using webpack.

@github-actions github-actions bot added Module Resolution Module resolution (CJS / ESM, module resolving). Webpack Related to Webpack with Next.js. labels Apr 13, 2025
@bartlangelaan bartlangelaan changed the title Cannot import @mui/material from a CJS dependency Cannot import @mui/material from a ESM dependency Apr 13, 2025
@bartlangelaan bartlangelaan changed the title Cannot import @mui/material from a ESM dependency Cannot import @mui/material from an ESM dependency Apr 13, 2025
@Janpot
Copy link
Contributor

Janpot commented Apr 18, 2025

Hi, I'm from the MUI team and just stumbled onto this issue. In @mui/material@7 we've fixed our package layout and with this version it should be possible to correctly import from a ESM only module. If you should encounter the problem with v7 as well, we encourage you to open a ticket at https://github.com/mui/material-ui/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module Resolution Module resolution (CJS / ESM, module resolving). Webpack Related to Webpack with Next.js.
Projects
None yet
Development

No branches or pull requests

3 participants
@bartlangelaan @Janpot and others