-
Notifications
You must be signed in to change notification settings - Fork 915
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
[BUG] material-ui not built correctly(?) #3004
Comments
I second this issue. MUI build fails with @material-ui/lab on the latest version of snowpack |
downgrade to snowpack 3.0.13 will fix |
I hope this is a temporary solution This also don't work for me |
@i3ima try run |
Same issues on my end
in code: in console:
|
I had to revert my version of snowpack AND change my imports to defaults instead of destructured. |
@awburgard unfortunately, it's not my case. I have a pretty big application and will take a lot of time to replace destructured imports. |
This is working on latest master branch for me. So next release should have it fixed, I think. |
Latest works for me as well |
Seeing this, or a similar issue, on 3.3.5 with The file paths listed made me think it's maybe not picking up MUI's
|
So I've found the problem, at least in our case - Snowpack doesn't get along with Material UI's recommended import style. https://material-ui.com/getting-started/usage/#quick-start
As of Snowpack 3.x, I see that other posters above have slightly different errors than what we were seeing, but in case it helps anyone: Solution 1Add
Solution 2Since we're in the world of ES Modules now, just use MUI's barrel exports:
Solution 3?The simplest option would be an alias in the Snowpack config, but my attempt failed:
because Snowpack picks up
|
for those who are interested, here is a working example: https://github.com/Nexysweb/react-snowpack |
Well, the esm solution suggested by @jalovatt doesn't work for me since I was trying to use the And it still shows |
Similar to @vikigenius, I started having this SliderMark not having a default export error when I updated Material UI to version 5. I downgraded Material UI to latest stable version (4.11.4 as of now) and now it works on current snowpack version (3.5.1). I was trying to install the new version of Material UI to get rid of this React Strict Mode error/warning regarding |
This seems to affect any css that is imported from npm. |
Can confirm that it works with Snowpack v3.0.13. |
Narrowed it down to the commit that causes this issue. Stems from this big internal rewrite of Snowpack: bea1c56 The commit prior to the one above worked fine. Will take a look at it during my free time. Not familiar with Snowpack internals. |
@shripadk great find. It seems like a huge rewrite though, I am not sure how easy it will be to figure it out. Maybe someone from the dev team can help on this. Probably has something to do with ES6 modules. MUI did change a lot of things recently regarding that like this mui/material-ui#26310. It could also explain why some of the suggested workarounds for MUI 4 don't work for MUI 5 alpha releases. |
Additional point to note is that the prod build But the dev build |
@vikigenius Yep can confirm! Production build works fine. Not Development server. This is definitely a bug with Snowpack and not with Material UI. |
In our case we tried adding many aliases like the following: // snowpack.config.js
{
alias: {
'@material-ui/core/Avatar': '@material-ui/core/esm/Avatar',
'@material-ui/lab/Alert': '@material-ui/lab/esm/Alert',
}
} so that we didn't have to change every single Material UI import in the project (there are tons of imports!) like such: import Typography from '@material-ui/core/Typography'
// -->
import Typography from '@material-ui/core/esm/Typography'
// or even
import { Typography } from '@material-ui/core' It worked fine for dev builds but when creating a production build I would get the error:
Here's a reproducible example for my case if it's of any help, though it seems like most big findings have already been discovered in this thread!
|
I took a look at the cache that snowpack is building for the dev server.
The second line that tries to export all these different classes is what's causing the error. Two things standout.
@drwpow I am hoping this helps you out. |
👋🏻 Thanks so much everyone for reporting on this issue. I think with the most recent 4.x and 5.x versions of In general If someone here could open an issue on the Material UI repo to implement Node’s new ESM guidelines, I think most if not all of the issues would be resolved. Not only for Snowpack users, but for Node ESM as a whole. |
@drwpow looks like the issue with The workaround I suggested with modifying the cache still works. From the discussion on What would be the action plan here? Is there a way we can work around that from snowpack itself ? |
@drwpow is there any update or plan regarding this issue? My team is currently trying to cut over to snowpack, but the issues with material-ui have become blockers. Thanks in advance |
Can we skip the material-ui package from being in Snowpack cache? Would that help? Or otherwise import from an already built/bundled source of Material UI? I don't have any hopes of MUI changing things, regardless of what the ESM guidelines are, as they do very non-standard things to begin with (ie. log warnings at the error level). So I'm just wondering if it's possible to work around MUI. |
@tmaiaroto that seems reasonable to me. Is there any configuration way to accomplish this at the moment without breaking the node modules patterns in the project? |
This is a tough/impossible problem to fix on Snowpack’s side. To the answer of “can we skip the material-ui package from being in Snowpack cache,“ the answer is no simply because material-ui doesn’t ship browser-compatible code (ESM). They ship CommonJS. The simplest fix would be for material-ui to ship ESM code, but as @vikigenius has already pointed out, the team has said they’re unwilling to do the work. Of course, the Snowpack project does its best to upconvert whatever CommonJS to ESM it can, but it’s an imperfect process, and while it works for many packages, it can’t always work for every package perfectly (because we’re changing the code from how it was originally designed/written). Sure, webpack goes through a similar transformation, but the difference is that a) material-ui is testing and designing for webpack’s specific transformations, and b) Snowpack takes the extra step of upconverting from CJS to ESM, which webpack does not do. And between all of these differences, material-ui hasn’t designed their package to be ESM-compatible (i.e. easily compatible with Snowpack). Solving package issues where the original team won’t ship modern code is like a game of whack-a-mole. Changing how Snowpack handles one package could lead to breaking others, and we’re just shooting for wide support. So as much as I hate to say it, the quickest way to use material-ui is to use webpack, or give Vite a try (I don’t know if it works on Vite, but some packages work better on Snowpack and some on Vite, and this may be one of the latter). |
But snowpack 3.0.13 somehow can handle that import system and start dev server on every material ui version i have tried. Why newer versions cant do that? |
Was wondering the same, we are still running 3.0.13 as well at the moment. Seems the big refactor fixed some issues but led to big regressions that are difficult to get a handle one |
I wanted to also interject that for me, the solution to getting it to build with import AppBar from '@mui/material/AppBar'; instead of using: import { AppBar } from '@mui/material'; Hope this helps someone as lost as I was! |
This works for some of the MUI components, I'm having issues if I try to use e.g. Menu or Drawer Here's a working sample on CodeSandbox: https://codesandbox.io/s/reverent-lake-k8xuo?file=/src/Layout.tsx The above does not build/run for me with Snowpack. |
In case anyone stumbles across this and is similarly stumped, the issue appears to be with circular references. There is a workaround suggested here: This worked in my case, using e.g. Drawer: It looks like the MUI team are aware of the issue, also: |
Bug Report Quick Checklist
Describe the bug
I tried migrating a project from CRA to SCA, but am getting issues with material-ui.
See screenshot:
To Reproduce
Expected behavior
I would have assumed that react is not throwing an error and that snowpack would've "packed" the exported darken function from
node_modules/@material-ui/core/esm/styles/colorManipulator.js:245
into the requested/_snowpack/pkg/@material-ui.core.styles.v4.11.3.js
The text was updated successfully, but these errors were encountered: