Material-ui: Build breaks on Webpack 5

Created on 28 Oct 2020  路  12Comments  路  Source: mui-org/material-ui


Build breaks on Webpack 5 due to babel-runtime imports not following ESM Strict mode requirements.

  • [X] The issue is present in the latest release.
  • [X] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

Build fails with the following errors:

> yarn build
yarn build
yarn run v1.22.5
$ cross-env NODE_ENV=production webpack --config=config/webpack.config.js
[webpack-cli] Compilation finished
assets by status 580 KiB [cached] 3 assets
orphan modules 782 KiB [orphan] 201 modules
runtime modules 6.08 KiB 10 modules
modules by path ./node_modules/@material-ui/ 1.22 MiB 202 modules
modules by path ./node_modules/@babel/runtime/helpers/ 7.4 KiB 19 modules
modules by path ./node_modules/prop-types/ 2.58 KiB 3 modules
modules by path ./src/ 79.5 KiB 2 modules
modules by path ./node_modules/react/ 6.48 KiB 2 modules
modules by path ./node_modules/react-dom/ 119 KiB 2 modules
modules by path ./node_modules/scheduler/ 4.91 KiB 2 modules
modules by path ./node_modules/react-is/ 2.69 KiB 2 modules
modules by path ./node_modules/react-transition-group/esm/ 18.2 KiB
  ./node_modules/react-transition-group/esm/Transition.js + 1 modules 18.1 KiB [built] [code generated]
  ./node_modules/react-transition-group/esm/TransitionGroupContext.js 68 bytes [built] [code generated]
9 modules

ERROR in ./node_modules/@babel/runtime/helpers/esm/inherits.js 1:0-46
Module not found: Error: Can't resolve './setPrototypeOf' in '/home/elias/dev/acto/react-template/node_modules/@babel/runtime/helpers/esm'
Did you mean 'setPrototypeOf.js'?
BREAKING CHANGE: The request './setPrototypeOf' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@material-ui/core/esm/RootRef/RootRef.js 3:0-60 50:2-11
 @ ./node_modules/@material-ui/core/esm/RootRef/index.js 1:0-36 1:0-36
 @ ./node_modules/@material-ui/core/index.js
 @ ./src/pages/LoginError.js 4:0-59 5:18-28 23:42-46
 @ ./src/App.js 8:0-44 25:15-25
 @ ./src/index.js 3:0-24 9:7-10

ERROR in ./node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js 1:0-74
Module not found: Error: Can't resolve './objectWithoutPropertiesLoose' in '/home/elias/dev/acto/react-template/node_modules/@babel/runtime/helpers/esm'
Did you mean 'objectWithoutPropertiesLoose.js'?
BREAKING CHANGE: The request './objectWithoutPropertiesLoose' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@material-ui/core/esm/Typography/Typography.js 2:0-90 172:14-38
 @ ./node_modules/@material-ui/core/esm/Typography/index.js 1:0-39 1:0-39
 @ ./src/pages/Login/Login.js 4:0-54 39:38-48 42:59-69
 @ ./src/App.js 6:0-40 17:15-20
 @ ./src/index.js 3:0-24 9:7-10

ERROR in ./node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js 1:0-47
Module not found: Error: Can't resolve '../../helpers/esm/typeof' in '/home/elias/dev/acto/react-template/node_modules/@babel/runtime/helpers/esm'
Did you mean 'typeof.js'?
BREAKING CHANGE: The request '../../helpers/esm/typeof' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@material-ui/core/esm/RootRef/RootRef.js 4:0-94 7:379-405
 @ ./node_modules/@material-ui/core/esm/RootRef/index.js 1:0-36 1:0-36
 @ ./node_modules/@material-ui/core/index.js
 @ ./src/pages/LoginError.js 4:0-59 5:18-28 23:42-46
 @ ./src/App.js 8:0-44 25:15-25
 @ ./src/index.js 3:0-24 9:7-10

ERROR in ./node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js 2:0-60
Module not found: Error: Can't resolve './assertThisInitialized' in '/home/elias/dev/acto/react-template/node_modules/@babel/runtime/helpers/esm'
Did you mean 'assertThisInitialized.js'?
BREAKING CHANGE: The request './assertThisInitialized' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@material-ui/core/esm/RootRef/RootRef.js 4:0-94 7:379-405
 @ ./node_modules/@material-ui/core/esm/RootRef/index.js 1:0-36 1:0-36
 @ ./node_modules/@material-ui/core/index.js
 @ ./src/pages/LoginError.js 4:0-59 5:18-28 23:42-46
 @ ./src/App.js 8:0-44 25:15-25
 @ ./src/index.js 3:0-24 9:7-10

ERROR in ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js 1:0-46
Module not found: Error: Can't resolve './arrayWithHoles' in '/home/elias/dev/acto/react-template/node_modules/@babel/runtime/helpers/esm'
Did you mean 'arrayWithHoles.js'?
BREAKING CHANGE: The request './arrayWithHoles' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@material-ui/core/esm/Zoom/Zoom.js 2:0-70 57:20-34
 @ ./node_modules/@material-ui/core/esm/Zoom/index.js 1:0-33 1:0-33
 @ ./node_modules/@material-ui/core/index.js
 @ ./src/pages/LoginError.js 4:0-59 5:18-28 23:42-46
 @ ./src/App.js 8:0-44 25:15-25
 @ ./src/index.js 3:0-24 9:7-10

ERROR in ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js 2:0-58
Module not found: Error: Can't resolve './iterableToArrayLimit' in '/home/elias/dev/acto/react-template/node_modules/@babel/runtime/helpers/esm'
Did you mean 'iterableToArrayLimit.js'?
BREAKING CHANGE: The request './iterableToArrayLimit' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@material-ui/core/esm/Zoom/Zoom.js 2:0-70 57:20-34
 @ ./node_modules/@material-ui/core/esm/Zoom/index.js 1:0-33 1:0-33
 @ ./node_modules/@material-ui/core/index.js
 @ ./src/pages/LoginError.js 4:0-59 5:18-28 23:42-46
 @ ./src/App.js 8:0-44 25:15-25
 @ ./src/index.js 3:0-24 9:7-10

ERROR in ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js 3:0-48
Module not found: Error: Can't resolve './nonIterableRest' in '/home/elias/dev/acto/react-template/node_modules/@babel/runtime/helpers/esm'
Did you mean 'nonIterableRest.js'?
BREAKING CHANGE: The request './nonIterableRest' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@material-ui/core/esm/Zoom/Zoom.js 2:0-70 57:20-34
 @ ./node_modules/@material-ui/core/esm/Zoom/index.js 1:0-33 1:0-33
 @ ./node_modules/@material-ui/core/index.js
 @ ./src/pages/LoginError.js 4:0-59 5:18-28 23:42-46
 @ ./src/App.js 8:0-44 25:15-25
 @ ./src/index.js 3:0-24 9:7-10

ERROR in ./node_modules/@babel/runtime/helpers/esm/toArray.js 1:0-46
Module not found: Error: Can't resolve './arrayWithHoles' in '/home/elias/dev/acto/react-template/node_modules/@babel/runtime/helpers/esm'
Did you mean 'arrayWithHoles.js'?
BREAKING CHANGE: The request './arrayWithHoles' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@material-ui/core/esm/ExpansionPanel/ExpansionPanel.js 2:0-58 138:31-39
 @ ./node_modules/@material-ui/core/esm/ExpansionPanel/index.js 1:0-43 1:0-43
 @ ./node_modules/@material-ui/core/index.js
 @ ./src/pages/LoginError.js 4:0-59 5:18-28 23:42-46
 @ ./src/App.js 8:0-44 25:15-25
 @ ./src/index.js 3:0-24 9:7-10

ERROR in ./node_modules/@babel/runtime/helpers/esm/toArray.js 2:0-48
Module not found: Error: Can't resolve './iterableToArray' in '/home/elias/dev/acto/react-template/node_modules/@babel/runtime/helpers/esm'
Did you mean 'iterableToArray.js'?
BREAKING CHANGE: The request './iterableToArray' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@material-ui/core/esm/ExpansionPanel/ExpansionPanel.js 2:0-58 138:31-39
 @ ./node_modules/@material-ui/core/esm/ExpansionPanel/index.js 1:0-43 1:0-43
 @ ./node_modules/@material-ui/core/index.js
 @ ./src/pages/LoginError.js 4:0-59 5:18-28 23:42-46
 @ ./src/App.js 8:0-44 25:15-25
 @ ./src/index.js 3:0-24 9:7-10

ERROR in ./node_modules/@babel/runtime/helpers/esm/toArray.js 3:0-48
Module not found: Error: Can't resolve './nonIterableRest' in '/home/elias/dev/acto/react-template/node_modules/@babel/runtime/helpers/esm'
Did you mean 'nonIterableRest.js'?
BREAKING CHANGE: The request './nonIterableRest' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@material-ui/core/esm/ExpansionPanel/ExpansionPanel.js 2:0-58 138:31-39
 @ ./node_modules/@material-ui/core/esm/ExpansionPanel/index.js 1:0-43 1:0-43
 @ ./node_modules/@material-ui/core/index.js
 @ ./src/pages/LoginError.js 4:0-59 5:18-28 23:42-46
 @ ./src/App.js 8:0-44 25:15-25
 @ ./src/index.js 3:0-24 9:7-10

ERROR in ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js 1:0-52
Module not found: Error: Can't resolve './arrayWithoutHoles' in '/home/elias/dev/acto/react-template/node_modules/@babel/runtime/helpers/esm'
Did you mean 'arrayWithoutHoles.js'?
BREAKING CHANGE: The request './arrayWithoutHoles' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@material-ui/core/esm/GridListTile/GridListTile.js 3:0-78 51:72-90 53:71-89 57:74-92 59:71-89
 @ ./node_modules/@material-ui/core/esm/GridListTile/index.js 1:0-41 1:0-41
 @ ./node_modules/@material-ui/core/index.js
 @ ./src/pages/LoginError.js 4:0-59 5:18-28 23:42-46
 @ ./src/App.js 8:0-44 25:15-25
 @ ./src/index.js 3:0-24 9:7-10

ERROR in ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js 2:0-48
Module not found: Error: Can't resolve './iterableToArray' in '/home/elias/dev/acto/react-template/node_modules/@babel/runtime/helpers/esm'
Did you mean 'iterableToArray.js'?
BREAKING CHANGE: The request './iterableToArray' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@material-ui/core/esm/GridListTile/GridListTile.js 3:0-78 51:72-90 53:71-89 57:74-92 59:71-89
 @ ./node_modules/@material-ui/core/esm/GridListTile/index.js 1:0-41 1:0-41
 @ ./node_modules/@material-ui/core/index.js
 @ ./src/pages/LoginError.js 4:0-59 5:18-28 23:42-46
 @ ./src/App.js 8:0-44 25:15-25
 @ ./src/index.js 3:0-24 9:7-10

ERROR in ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js 3:0-52
Module not found: Error: Can't resolve './nonIterableSpread' in '/home/elias/dev/acto/react-template/node_modules/@babel/runtime/helpers/esm'
Did you mean 'nonIterableSpread.js'?
BREAKING CHANGE: The request './nonIterableSpread' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@material-ui/core/esm/GridListTile/GridListTile.js 3:0-78 51:72-90 53:71-89 57:74-92 59:71-89
 @ ./node_modules/@material-ui/core/esm/GridListTile/index.js 1:0-41 1:0-41
 @ ./node_modules/@material-ui/core/index.js
 @ ./src/pages/LoginError.js 4:0-59 5:18-28 23:42-46
 @ ./src/App.js 8:0-44 25:15-25
 @ ./src/index.js 3:0-24 9:7-10

webpack 5.3.0 compiled with 13 errors in 7265 ms
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expected Behavior 馃

Build finishes without errors.

Steps to Reproduce 馃暪

  1. Setup a React project with MUI and Webpack 5
  2. Build project
  3. :boom:

Context 馃敠

Migration from Webpack 4 -> 5, which imposes stricter requirements for package modules.

Your Environment 馃寧

| Tech | Version |
| ----------- | ------- |
| Material-UI | v4.11.0 |
| React | v17.0.1 (also happens with newest v16 release) |
| Browser | N/A |
| TypeScript | N/A |
| Webpack | 5.3.0 |

incomplete

Most helpful comment

I deleted it, reinstalled my deps, and profit.

If I recall correctly, some versions of babel/runtime are just not compatible with webpack 5. We're probably bumping our version to the latest in v5 but for v4 I rather not mess with babel/runtime.

All 12 comments

Should be fixed by updating babel-runtime to 7.12.0 or newer, as noted here: https://babeljs.io/blog/2020/10/15/7.12.0

It doesn't look like this bug report has enough info for one of us to reproduce it.

Please provide a CodeSandbox (https://material-ui.com/r/issue-template), a link to a repository on GitHub, or provide a minimal code example that reproduces the problem.

Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve

@eps1lon Afaik codesandbox does not support custom webpack configs. I'll create a quick repo showcasing the issue.

I'll create a quick repo showcasing the issue.

That's fine. That is a saved reply that mentions that codesandbox is not necessary. GitHub repo works just as well.

I'm gonna close the issue. After creating the example where it oddly worked just fine, i came to the conclusion that it had to be the yarn.lock file, as all else was identical. I deleted it, reinstalled my deps, and profit.

I deleted it, reinstalled my deps, and profit.

If I recall correctly, some versions of babel/runtime are just not compatible with webpack 5. We're probably bumping our version to the latest in v5 but for v4 I rather not mess with babel/runtime.

Still not working for me today, having the same issues as described. Does that mean we will have to wait for V5 to work with the latest babel version??

@anthonyferreol Try deleting your lock file and reinstall your projects dependencies. It did the trick for me, for some reason.

I tried the package-lock.json delete and it didn't help. I can't upgrade to webpack 5 because of this... PLEASE FIX. I can't believe we have to wait for V5 in order to be able to use the latest webpack. What is the ETA on material-ui@v5?

@EliasJorgensen I tried before posting, it is not working

Until the version of Babel runtime is not bumped in material-ui, I'm doomed with my up to date tech stack 馃槬

@anthonyferreol Sorry to hear that. It worked for me.

@EliasJorgensen

Try deleting your lock file and reinstall your projects dependencies. It did the trick for me, for some reason.

This worked for me Thanks!

Was this page helpful?
0 / 5 - 0 ratings