-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[ESM] Publish packages in ESM module format #30671
Comments
I think this should probably be extracted out into a separate issue, as it would be a boon to using Material UI natively in a browser (without a bundler/transpiler), I think even without addressing the other things mentioned here (I could be wrong though). |
Publint is reporting that the components are written in ESM but getting interpreted as CJS. I tried the MUI imports in a Next.js project with Is this because Next.js is reading the CJS exports under |
In order to be able to use import { LockOutlined } from '@mui/icons-material'; I believe it relies on the presence of |
This seems to be a blocker for getting MUI components to play nicely with Remix. Named imports appear to work fine. ❌ import Box from "@mui/joy/Box";
✅ import { Box } from "@mui/material"; |
As a workaround, you can do for now the following search-and-replace with regex to fix it: |
Add .js Add more .js DEBUG: comment out text editor and all icon. Rendering ok now add workaround for @mui/icons-material not published in ESM module format See mui/material-ui#30671 (comment). add workaround for react-ace not published in ESM module format See securingsincity/react-ace#1540 (comment).
Add .js Add more .js DEBUG: comment out text editor and all icon. Rendering ok now add workaround for @mui/icons-material not published in ESM module format See mui/material-ui#30671 (comment). add workaround for react-ace not published in ESM module format See securingsincity/react-ace#1540 (comment).
Add .js Add more .js DEBUG: comment out text editor and all icon. Rendering ok now add workaround for @mui/icons-material not published in ESM module format See mui/material-ui#30671 (comment). add workaround for react-ace not published in ESM module format See securingsincity/react-ace#1540 (comment).
Add .js Add more .js DEBUG: comment out text editor and all icon. Rendering ok now add workaround for @mui/icons-material not published in ESM module format See mui/material-ui#30671 (comment). add workaround for react-ace not published in ESM module format See securingsincity/react-ace#1540 (comment).
Add .js Add more .js DEBUG: comment out text editor and all icon. Rendering ok now add workaround for @mui/icons-material not published in ESM module format See mui/material-ui#30671 (comment). add workaround for react-ace not published in ESM module format See securingsincity/react-ace#1540 (comment).
Add .js Add more .js DEBUG: comment out text editor and all icon. Rendering ok now add workaround for @mui/icons-material not published in ESM module format See mui/material-ui#30671 (comment). add workaround for react-ace not published in ESM module format See securingsincity/react-ace#1540 (comment).
Add .js Add more .js DEBUG: comment out text editor and all icon. Rendering ok now add workaround for @mui/icons-material not published in ESM module format See mui/material-ui#30671 (comment). add workaround for react-ace not published in ESM module format See securingsincity/react-ace#1540 (comment).
Output .cjs file, set it under package.json should make it possible use it with tsconfig esModuleInterop: true. Currently you can't do anything in esm configured project, because there is just a .js file in the build. And this .js file uses esm syntax. Having this issue with the AdapterXYZ exports - date-pickers. |
Requirement for both CommonJS and ESM support from Docker: https://app.supernormal.com/posts/mui-docker-x-charts-6b722290c9c8013c6d350e8110019023 |
Would be interested in what those infrastructure requirements are exactly. What mandates the need for a commonjs bundle? Does their bundler not understand ESM? Or does their SSR setup not compile modules on the server? It's an odd choice to try and fix this by adding a commonjs version to their chart library, rather than to force their bundler to transpile the dependency. |
Sadly, I'm removing this issue from the v6 milestone, tentatively moving it to v7. I'll write an in-depth document on what we tried, why we're blocked, and the steps forward. As a summary, we found a blocker with Next.js Pages Router: vercel/next.js#65056. The probable path forward is removing the
|
Just recording some tips for anyone that wants to debug this:
It looks like webpack isn't using the ESM bundle of
|
Currently the issue is maximized in the sense of blocking every possible simple workaround at once, by exporting .js, not .cjs (for interop workaround TS) or .mjs and at the same time using esm syntax in the .js build: |
I've gotten used to copy-pasting icons from the website into my project. I forgot about this issue and accidentally broke my app in dev. That's why I went out of my way to prevent this from happening in the future by adding an eslint rule to prevent imports of the icons as in the copypasta:
|
Why
experimental.esmxternals
). Could help with [styled-engine-sc] MUI + styled-components + Next.js CSS rules ordering issue #29742 (comment) to givebabel-plugin-styled-components
a source that is easier to statically analyze.It looks like it’s trying to convert back the commonjs version into ESM and getting confused (this is a non-deterministic process, best effort). It seems to resolve the package specifier to the commonjs module instead of ESM
How
Early attempt: Draft: Try converting packages to ESM #30510
Figure out what happened with these PRs and verify whether the problem is still relevant:
In our build output, make sure ESM files get the extension
.mjs
. We can probably start with this and maybe even release on a minorpackage.json
: dual ESM/commonjs: https://nodejs.org/api/packages.html#dual-commonjses-module-packages"type": "module"
until v7?Internal imports will need file extensions https://github.com/jaydenseric/babel-plugin-transform-require-extensions. We can probably also consider releasing this on a minor version
How do we deal with
process.env.NODE_ENV
(e.g. https://github.com/mui-org/material-ui/blob/1230b1a571942f1abf2fec81812b757ceb0e5d0b/packages/mui-system/src/spacing.js#L104)? It will break when run as a module in the browser.Perhaps:
This doesn't work with react <=17: Bug: Cannot import 'react/jsx-runtime' from esm node/webpack 5 facebook/react#20235, We may be stuck on this until package exports are backported to react 17 (or when we can bump our
react
peer dependency >=18).The text was updated successfully, but these errors were encountered: