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

Issues with esbuild #31835

Closed
Tracked by #39765
arpitdalal opened this issue Mar 16, 2022 · 63 comments · Fixed by swarmion/swarmion#317
Closed
Tracked by #39765

Issues with esbuild #31835

arpitdalal opened this issue Mar 16, 2022 · 63 comments · Fixed by swarmion/swarmion#317
Assignees
Labels
core Infrastructure work going on behind the scenes external dependency Blocked by external dependency, we can’t do anything about it

Comments

@arpitdalal
Copy link

arpitdalal commented Mar 16, 2022

Current behavior 😯

Look at this issue for more reference: #31140
The essence of it is that esbuild might not be building MUI dependencies properly so when accessing MUI functions like createTheme and useEnhancedEffect give an error in run time. The issue referenced above is more with Remix but since @jacobgad faced the same issue with Vite and that also uses esbuild, I am more leaned towards this issue is related to esbuild than Remix or Vite.

Expected behavior 🤔

No Uncaught TypeError: createTheme_default is not a function or Uncaught TypeError: useEnhancedEffect_default is not a function run-time errors

Steps to reproduce 🕹

Steps:

  1. fork this codesandbox and use useEnhancedEffect from MUI instead of the custom one
  2. go to ErrorBoundary or CatchBoundary by clicking the link
  3. refreshing the page (the site in codesandbox not the codesandbox itself)
  4. open the console t see the error

Context 🔦

Was just trying to figure out how to have a complete theme change experience with MUI and Remix but found this problem with esbuild (likely)

Your environment 🌎

`npx @mui/envinfo`
  System:
    OS: Linux 5.4 Debian GNU/Linux 10 (buster) 10 (buster)
  Binaries:
    Node: 14.18.1 - ~/.nvm/versions/node/v14.18.1/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v14.18.1/bin/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.18.1/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: Not Found
  npmPackages:
    @emotion/react: latest => 11.8.2
    @emotion/styled: latest => 11.8.1
    @mui/base:  5.0.0-alpha.72
    @mui/icons-material: latest => 5.5.1
    @mui/material: latest => 5.5.1
    @mui/private-theming:  5.4.4
    @mui/styled-engine:  5.4.4
    @mui/system:  5.5.1
    @mui/types:  7.1.3
    @mui/utils:  5.4.4
    @types/react: latest => 17.0.40
    react: latest => 17.0.2
    react-dom: latest => 17.0.2
    typescript: latest => 4.6.2
@arpitdalal arpitdalal added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 16, 2022
@arpitdalal
Copy link
Author

cc: @mnajdova and @jacobgad

@infinia-yzl
Copy link

infinia-yzl commented May 20, 2022

Encountered a similar issue using Vite.

This (sometimes) resolves it temporarily for me:

  1. Comment <ThemeProvider> and <CssBaseline> and save.
  2. npm start or npm run dev.
  3. Uncomment <ThemeProvider> and <CssBaseline> and save.
  4. Vite updates and it works.

image
image
image

There were times where I tried the steps above and it simply would throw the same error at step 3.

@John0x
Copy link

John0x commented May 21, 2022

Experiencing this as well with vite

@tombohub
Copy link

tombohub commented May 25, 2022

@arpitdalal did you try to remove icons from page: #32891 ?

@tombohub
Copy link

tombohub commented Jun 4, 2022

any solution so far?

@michaldudak
Copy link
Member

@arpitdalal I'm trying to reproduce the error using the codesandbox you provided, but I'm unable to. Perhaps a more recent version of dependencies could solve the problem. Could you please verify if that's the case?

I was also trying to investigate the issue using plain esbuild, but I also wasn't able to make it fail.

@michaldudak michaldudak added external dependency Blocked by external dependency, we can’t do anything about it core Infrastructure work going on behind the scenes and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jun 5, 2022
@fullstackwebdev
Copy link

fullstackwebdev commented Jun 6, 2022

in my theme.ts, if I use below, I can reproduce the issue: createTheme_default is not a function

import { createTheme } from '@mui/material/styles';

But if I use this line below, it fixes it:

import { createTheme } from '@mui/material';

remix / material, all npm "latest"

@jmaldon1
Copy link

jmaldon1 commented Jun 10, 2022

I was getting the Uncaught TypeError: createTheme_default is not a function issue with remix, it had to do with the <CssBaseline />.

If your project was set up using the Remix MUI Example, then the fix for me was to add the <CssBaseline /> to the Layout.tsx file. Like so:

import * as React from "react";
import Container from "@mui/material/Container";
import Box from "@mui/material/Box";
import CssBaseline from "@mui/material/CssBaseline";

export default function Layout({ children }: { children: React.ReactNode }) {
  return (
    <Container maxWidth="sm">
      <Box sx={{ my: 4 }}>
        <CssBaseline />
        {children}
      </Box>
    </Container>
  );
}

although, still getting TypeError: useEnhancedEffect_default is not a function. Which seems to be fixed when I add icons (@mui/icons-material) to the page... not idea why.

Final Update:
After reading #31140 (comment), I downgraded mui to 5.4.1 and I no longer get the TypeError: useEnhancedEffect_default is not a function. So seems like there is a bug that still needs to be resolved in mui.

@geneshairzan
Copy link

experice same issue..

still can find the root cause of the problem..

iam using vite v2.9.9 & "@mui/material": "^5.8.0",

my temp fix,
make error in vite config, undo, recompile

my problem somewhere near :
import Box from "@mui/material/Box";
i changed into :
import {Box}from "@mui/material";

@akshayitzme
Copy link

akshayitzme commented Jun 14, 2022

thanks @geneshairzan your temp fix worked for me

my error was
Box.js:5 undefined is not a function

seems to be fixed by changing
import Box from "@mui/material/Box"; this line

to this
import {Box} from "@mui/material";

@jyoketsu
Copy link

experice same issue..

still can find the root cause of the problem..

iam using vite v2.9.9 & "@mui/material": "^5.8.0",

my temp fix, make error in vite config, undo, recompile

my problem somewhere near : import Box from "@mui/material/Box"; i changed into : import {Box}from "@mui/material";

worked! thanks

@arpitdalal
Copy link
Author

@arpitdalal I'm trying to reproduce the error using the codesandbox you provided, but I'm unable to. Perhaps a more recent version of dependencies could solve the problem. Could you please verify if that's the case?

I was also trying to investigate the issue using plain esbuild, but I also wasn't able to make it fail.

@michaldudak I haven't tried reproducing this error by using just esbuild because I do not have the knowledge to create a raw project with esbuild. But I can definitely reproduce this with Remix's esbuild config. Here's a sandbox with the latest dependencies which uses unstable_useEnhancedEffect from @mui/material pkg in the root.tsx.

Steps to reproduce:

open the site > click on any link > open dev console > hard refresh with ctrl + shift + R (w/e it is for macos). You should see the page breaking with the first error other than react 18 warning will be Uncaught TypeError: useEnhancedEffect_default is not a function which causes a chain of errors resulting in a broken page.

Temporary workaround:

in the codesandbox comment the line 19 and uncomment line 24 which uses the custom useEnhancedEffect. Once done, hard refresh the site and re-try the above steps and the page shouldn't break.


I can confirm that this is related to the @mui/icons-material pkg

Steps to reproduce:

same steps to reproduce as above

Temporary workaround:

open the codesnadbox > comment lines 3, 4, and 42 > uncomment line 43 > this way app is not using @mui/icons-material pkg anywhere, so esbuild won't build that dependency and then retry the above steps of going to the error/catch boundary and hard-refreshing, you shouldn't see any errors related to useEnhancedEffect_default


I want to throw some light on the fact that this only happens when the error/catch boundary is hard-refreshed, meaning SSR'ed, if client-side navigated to these pages, it doesn't break the page.

@Nkzn
Copy link
Contributor

Nkzn commented Aug 4, 2022

in my environment

// Failure
import Box from '@mui/material/Box';
import CssBaseline from '@mui/material/CssBaseline';

// OK
import CssBaseline from '@mui/material/CssBaseline';
import Box from '@mui/material/Box';

// Also OK
import { Box } from '@mui/material';
import CssBaseline from '@mui/material/CssBaseline';

@williamrjribeiro
Copy link

Today I encountered this issue after installing @mui/icons-material to my Remix project.

My workaround was to use Icon Fonts. Hopefully the root issue will be fixed soon.

@ViniciusMRosa
Copy link

Today I encountered this issue after installing @mui/icons-material to my Remix project.

My workaround was to use Icon Fonts. Hopefully the root issue will be fixed soon.

The same here, thanks for sharing @williamrjribeiro

@jmsbrett
Copy link

jmsbrett commented Aug 30, 2022

I had this issue and could not solve it with the above solutions.

Uninstalling and re-installing then rebuild worked for me:

npm uninstall @mui/icons-material @mui/material
npm install @mui/icons-material @mui/material

@CRIMSON-CORP
Copy link

experice same issue..

still can find the root cause of the problem..

iam using vite v2.9.9 & "@mui/material": "^5.8.0",

my temp fix, make error in vite config, undo, recompile

my problem somewhere near : import Box from "@mui/material/Box"; i changed into : import {Box}from "@mui/material";

thanks to @geneshairzan, its kind of absurd, but causing error in vite.config.js and restarting the server after the crash actually solves my problem, I'm not sure why, i kept on getting - Uncaught TypeError: createTheme_default is not a function even after trying every solution in this issue

@MA-MacDonald
Copy link

I'm running into the same issue...
I'm using Vite v3.1.6

I'm importing all of my Box components like the following but still receiving the error
import {Box} from "@mui/material";

image

@mnajdova
Copy link
Member

the same here
I solved with
import { Box } from '@mui/material';
but with that I end up losing the layout style

All import should work if they are imported from top level: '@mui/material' for e.g.

@juliomiguel
Copy link

For those who are having the problem with Vite, I solved it the same way (upgrading the imports to a higher level). If the problem continues, just delete the "node_modules" folder and then reinstall all dependencies.

@kishore-s-15
Copy link

Resolved it by changing import Box from "@mui/material/Box" to import {Box} from "@mui/material". By changing the imports, prettier has pushed the Box import below the CSSBaseline import. Can anyone explain why this error occurs?

shs96c added a commit to shs96c/selenium that referenced this issue Feb 8, 2024
Also builds the Grid UI using `esbuild`.

The weird imports in the Grid UI are due to an issue with the way that
`esbuild` interacts with `@mui/material-icons`:

mui/material-ui#31835 (comment)
shs96c added a commit to shs96c/selenium that referenced this issue Feb 22, 2024
Also builds the Grid UI using `esbuild`.

The weird imports in the Grid UI are due to an issue with the way that
`esbuild` interacts with `@mui/material-icons`:

mui/material-ui#31835 (comment)
shs96c added a commit to shs96c/selenium that referenced this issue Mar 6, 2024
Also builds the Grid UI using `esbuild`.

The weird imports in the Grid UI are due to an issue with the way that
`esbuild` interacts with `@mui/material-icons`:

mui/material-ui#31835 (comment)
shs96c added a commit to shs96c/selenium that referenced this issue Mar 6, 2024
Also builds the Grid UI using `esbuild`.

The weird imports in the Grid UI are due to an issue with the way that
`esbuild` interacts with `@mui/material-icons`:

mui/material-ui#31835 (comment)
shs96c added a commit to shs96c/selenium that referenced this issue Mar 8, 2024
Also builds the Grid UI using `esbuild`.

The weird imports in the Grid UI are due to an issue with the way that
`esbuild` interacts with `@mui/material-icons`:

mui/material-ui#31835 (comment)
shs96c added a commit to shs96c/selenium that referenced this issue Mar 9, 2024
Also builds the Grid UI using `esbuild`.

The weird imports in the Grid UI are due to an issue with the way that
`esbuild` interacts with `@mui/material-icons`:

mui/material-ui#31835 (comment)
shs96c added a commit to shs96c/selenium that referenced this issue Mar 9, 2024
Also builds the Grid UI using `esbuild`.

The weird imports in the Grid UI are due to an issue with the way that
`esbuild` interacts with `@mui/material-icons`:

mui/material-ui#31835 (comment)
@gianglt
Copy link

gianglt commented Mar 16, 2024

I met this error when I was working with a Vite+React+TS application.
Wrapping technque as mentioned by divyam751 doesnt solve the problem.
Finally I overcame the error by editing vite.config.ts

export default defineConfig({
....
    optimizeDeps: {
        include: ['@mui/material/CssBaseline', '@mui/material/Box'],
        force: true
      },
...
})

Here, the both two lines are needed

shs96c added a commit to shs96c/selenium that referenced this issue Mar 20, 2024
Also builds the Grid UI using `esbuild`.

The weird imports in the Grid UI are due to an issue with the way that
`esbuild` interacts with `@mui/material-icons`:

mui/material-ui#31835 (comment)
shs96c added a commit to shs96c/selenium that referenced this issue Mar 20, 2024
Also builds the Grid UI using `esbuild`.

The weird imports in the Grid UI are due to an issue with the way that
`esbuild` interacts with `@mui/material-icons`:

mui/material-ui#31835 (comment)
shs96c added a commit to SeleniumHQ/selenium that referenced this issue Mar 20, 2024
Also builds the Grid UI using `esbuild`.

The weird imports in the Grid UI are due to an issue with the way that
`esbuild` interacts with `@mui/material-icons`:

mui/material-ui#31835 (comment)
@kemengwang
Copy link

This seems to be caused by node not getting the correct introduction when executing esm. You need to add type:module or exports:{import: "xx.mjs"} to each package.json of mui. If there is no these, the module will be introduced according to commonjs to load the entry file of the main field.
Why can this problem be fixed by introducing @mui/material instead? This is because the main entry file of @mui/material is ./node/index.js, and its content has es compatible code, so no error will be reported.

jimniels added a commit to quadratichq/quadratic that referenced this issue Apr 22, 2024
@benjie
Copy link

benjie commented Apr 26, 2024

Adding --force to my vite command (vite --force --host) solved this for me following a @mui/* upgrade.

@dagda1
Copy link

dagda1 commented Jul 4, 2024

I just got this error again after I removed all the barrel files in a project.

This time around the fix was to change

import Box from '@mui/material/Box';

to

import { Box } from '@mui/material';

Is this something to do with treeshaking?

@josipfrljic94
Copy link

josipfrljic94 commented Jul 21, 2024

If you are using vite, just go and delete node_modules/@.vite/deps and run npm i. It fix my problem every time. It's some cache problem

@Hiradpi
Copy link

Hiradpi commented Aug 11, 2024

I met this error when I was working with a Vite+React+TS application. Wrapping technque as mentioned by divyam751 doesnt solve the problem. Finally I overcame the error by editing vite.config.ts

export default defineConfig({
....
    optimizeDeps: {
        include: ['@mui/material/CssBaseline', '@mui/material/Box'],
        force: true
      },
...
})

Here, the both two lines are needed

i love you men you have no idea i have been trying to fix this stupid issue for almost 6 hours
thank you a lot <3

@SaurabhLambore
Copy link

no need of other only do the

  1. Uninstall MUI:
    npm uninstall @mui/material @emotion/react @emotion/styled
    npm uninstall @mui/icons-material @mui/system

  2. After uninstalling, you can reinstall MUI by running:
    npm install @mui/material @emotion/react @emotion/styled
    npm install @mui/icons-material @mui/system

@Janpot
Copy link
Member

Janpot commented Sep 17, 2024

Even though it may not necessarily look like it, we have reason to believe that the root cause of this issue actually lies in @mui/icons-material and has now been resolved. This fix is available in version 6.1.0 and up. As such we are closing this and a few similar issues.

If you still run into issues after upgrading to >6.1.0, please open a new ticket, this will allow us to separate whatever problem is left from the rest of this ticket. Thank you for your patience.

@Janpot Janpot closed this as completed Sep 17, 2024
Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

We value your feedback @arpitdalal! How was your experience with our support team?
If you could spare a moment, we'd love to hear your thoughts in this brief Support Satisfaction survey. Your insights help us improve!

Jbekker added a commit to Jbekker/humble-interface that referenced this issue Oct 22, 2024
* Made sure that all materials are imported from the top level
* See issue mui/material-ui#31835
* Small cosmetic changes for the other mui/material imports
temptemp3 pushed a commit to HumbleOSS/humble-interface that referenced this issue Oct 23, 2024
* Migrate from webpack to vite

* Remove unnecessary dev dependencies

* Resolve issue for Buffer not being defined

* Change alias for source folder

* Fixed issue for createTheme_default being undefined

* Made sure that all materials are imported from the top level
* See issue mui/material-ui#31835
* Small cosmetic changes for the other mui/material imports

* Update mui to v6.1.5

* Remove deprecated ReactDOM.render
@devesh-ReluConsultancy
Copy link

devesh-ReluConsultancy commented Oct 28, 2024

For me anything above didn't fixed the issue, its a vite bug which i have temporarily fixed by :

  1. Go to node_modules/.vite/deps/your_chunk_fileName.js
  2. Search createTheme_default() and instead of calling it just use reference like createTheme_default , save file
  3. Restart the vite server by making an error in vite.config.ts & run.
    Although its not a permanent fix but it does the job as in production build i didn't have this error , its only in dev environment.

prince-hope1975 pushed a commit to prince-hope1975/humble-interface that referenced this issue Nov 1, 2024
* Migrate from webpack to vite

* Remove unnecessary dev dependencies

* Resolve issue for Buffer not being defined

* Change alias for source folder

* Fixed issue for createTheme_default being undefined

* Made sure that all materials are imported from the top level
* See issue mui/material-ui#31835
* Small cosmetic changes for the other mui/material imports

* Update mui to v6.1.5

* Remove deprecated ReactDOM.render
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes external dependency Blocked by external dependency, we can’t do anything about it
Projects
None yet
Development

Successfully merging a pull request may close this issue.