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

Dependencies with exports field break on pages router with esmExternals: false #65056

Open
DiegoAndai opened this issue Apr 25, 2024 · 1 comment
Labels
bug Issue was opened via the bug report template. Pages Router Related to Pages Router.

Comments

@DiegoAndai
Copy link

DiegoAndai commented Apr 25, 2024

Link to the code that reproduces this issue

https://github.com/DiegoAndai/esm-test-13-nextjs-pages-mui-exports-ts

To Reproduce

  1. Clone https://github.com/DiegoAndai/esm-test-13-nextjs-pages-mui-exports-ts
  2. Run npm install
  3. Run npm run dev
  4. Open http://localhost:3000 in the browser
  5. You should see the error

Description

We're trying to add the exports field to the package.json of MUI core libraries (PR | Docs).
This app is using the MUI libraries from the PR build (e.g., https://pkg.csb.dev/mui/material-ui/commit/fb7a4ff2/@mui/material).
When testing the libraries on a Next.js app with pages router and esmExternals: false, we get the following error:

⨯ TypeError: _mui_utils_deepmerge__WEBPACK_IMPORTED_MODULE_3__ is not a function
Full error
 ⨯ TypeError: _mui_utils_deepmerge__WEBPACK_IMPORTED_MODULE_3__ is not a function
    at createPalette (webpack-internal:///./node_modules/@mui/material/styles/createPalette.mjs:266:27)
    at createTheme (webpack-internal:///./node_modules/@mui/material/styles/createTheme.mjs:47:83)
    at eval (webpack-internal:///./node_modules/@mui/material/styles/defaultTheme.mjs:7:82)
    at ./node_modules/@mui/material/styles/defaultTheme.mjs (/Users/diegoandai/MUI/experiments/esm-test-13-nextjs-pages-mui-exports-ts/.next/server/vendor-chunks/@mui.js:260:1)
    at __webpack_require__ (/Users/diegoandai/MUI/experiments/esm-test-13-nextjs-pages-mui-exports-ts/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///./node_modules/@mui/material/styles/styled.mjs:8:75)
    at ./node_modules/@mui/material/styles/styled.mjs (/Users/diegoandai/MUI/experiments/esm-test-13-nextjs-pages-mui-exports-ts/.next/server/vendor-chunks/@mui.js:310:1)
    at __webpack_require__ (/Users/diegoandai/MUI/experiments/esm-test-13-nextjs-pages-mui-exports-ts/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///./node_modules/@mui/material/Button/Button.mjs:13:77)
    at ./node_modules/@mui/material/Button/Button.mjs (/Users/diegoandai/MUI/experiments/esm-test-13-nextjs-pages-mui-exports-ts/.next/server/vendor-chunks/@mui.js:20:1)
    at __webpack_require__ (/Users/diegoandai/MUI/experiments/esm-test-13-nextjs-pages-mui-exports-ts/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///./node_modules/@mui/material/Button/index.mjs:6:69)
    at ./node_modules/@mui/material/Button/index.mjs (/Users/diegoandai/MUI/experiments/esm-test-13-nextjs-pages-mui-exports-ts/.next/server/vendor-chunks/@mui.js:40:1)
    at __webpack_require__ (/Users/diegoandai/MUI/experiments/esm-test-13-nextjs-pages-mui-exports-ts/.next/server/webpack-runtime.js:33:42)
    at __barrel_optimize__?names=Button!=!./node_modules/@mui/material/index.mjs (/Users/diegoandai/MUI/experiments/esm-test-13-nextjs-pages-mui-exports-ts/.next/server/pages/index.js:26:75) {
  page: '/'
}
 GET / 500 in 128ms

This seems related to default import/export interop between esm and cjs: https://www.typescriptlang.org/docs/handbook/modules/appendices/esm-cjs-interop.html

The expected is for the app to run without erroring.

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64
  Available memory (MB): 16384
  Available CPU cores: 16
Binaries:
  Node: 18.19.0
  npm: 10.4.0
  Yarn: 1.22.21
  pnpm: 8.14.1
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: 14.2.3
  react: 18.3.0
  react-dom: 18.3.0
  typescript: 5.4.5
Next.js Config:
  output: N/A

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

Pages Router

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

next dev (local)

Additional context

  • I've tested with Next.js 14.2.3, 13.5.1, and 13.4.0.
  • I tried to create a minimal repro, but I couldn't figure it out. I'm sorry about this.
@DiegoAndai DiegoAndai added the bug Issue was opened via the bug report template. label Apr 25, 2024
@github-actions github-actions bot added the Pages Router Related to Pages Router. label Apr 25, 2024
@DiegoAndai DiegoAndai changed the title Dependencies with exports field break on pages router with esmExternals: false Dependencies with exports field break on pages router with esmExternals: false | 'loose' Apr 25, 2024
@DiegoAndai DiegoAndai changed the title Dependencies with exports field break on pages router with esmExternals: false | 'loose' Dependencies with exports field break on pages router with esmExternals: false Apr 25, 2024
@DiegoAndai
Copy link
Author

Hey @huozhi, may I ask you to look into this issue and #64796? Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Pages Router Related to Pages Router.
Projects
None yet
Development

No branches or pull requests

1 participant