material-ui: Build breaks on Webpack 5

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

  • The issue is present in the latest release.
  • 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. 💥

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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

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

@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!

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

have this problem too. webpack 5.8.0 react 17.0.1 typescript 4.1.2

@material-ui/core 5.0.0-alpha.17 @material-ui/styled-engine 5.0.0-alpha.16


ERROR in ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js

Module not found: Error: Can’t resolve ‘./arrayWithoutHoles’ in ‘/usr/src/app/node_modules/@babel/runtime/helpers/esm’ … Module not found: Error: Can’t resolve ‘./iterableToArray’ in ‘/usr/src/app/node_modules/@babel/runtime/helpers/esm’ … Module not found: Error: Can’t resolve ‘./unsupportedIterableToArray’ in ‘/usr/src/app/node_modules/@babel/runtime/helpers/esm’ … Module not found: Error: Can’t resolve ‘./nonIterableSpread’ in ‘/usr/src/app/node_modules/@babel/runtime/helpers/esm’ … @ ./node_modules/css-vendor/dist/css-vendor.esm.js 2:0-78 408:18-36 @ ./node_modules/jss-plugin-vendor-prefixer/dist/jss-plugin-vendor-prefixer.esm.js 1:0-83 14:18-36 28:26-43 31:29-43 49:11-25 @ ./node_modules/@material-ui/styles/jssPreset/jssPreset.js 6:0-56 14:43-57 @ ./node_modules/@material-ui/styles/jssPreset/index.js 1:0-38 1:0-38 @ ./node_modules/@material-ui/styles/index.js 26:0-51 26:0-51 27:0-28 27:0-28 @ ./node_modules/@material-ui/core/styles/index.js 17:0-126 17:0-126 17:0-126 17:0-126 17:0-126 17:0-126

tried to delete lock file and install packages - the same errors

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.

@EliasJorgensen

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

Thanks, this worked for me! Although I had to delete the .next folder and node_modules also 👍

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.