Problem: When
--experimental-scope-hoisting
is used for tree shaking, the bundle builds, but the app fails with a runtime error when being served fromindex.html
.
// index.js
import React from 'react'
import { render } from 'react-dom'
// import [variations of Typograpy import here]
render(
<Typography>Hello</Typography>,
document.getElementById('app')
)
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>App</title>
</head>
<body>
<div id="app"></div>
<script src="index.js"></script>
</body>
</html>
"scripts": {
"start": "parcel index.html",
"build": "rm -rf dist && parcel build index.html",
"build:shake": "rm -rf dist && parcel build --experimental-scope-hoisting index.html",
"serve:dist": "serve dist"
},
"dependencies": {
"@material-ui/core": "^3.0.2",
"@material-ui/icons": "^3.0.1",
"react": "^16.4.2",
"react-dom": "^16.4.2"
},
"devDependencies": {
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"parcel-bundler": "^1.9.7",
"serve": "^10.0.0"
}
import Typography from '@material-ui/core/Typography'
197512 B
import { Typography } from '@material-ui/core'
657321 B
import Typography from '@material-ui/core/Typography'
153188 B "ReferenceError: React is not defined"
import { Typography } from '@material-ui/core'
199294 B "ReferenceError: React is not defined"
@material-ui/core/es
(ES Modules)
import Typography from '@material-ui/core/es/Typography'
193886 B
import { Typography } from '@material-ui/core/es'
648934 B
import Typography from '@material-ui/core/es/Typography'
174464 B "ReferenceError: React is not defined"
import { Typography } from '@material-ui/core/es'
220577 B "ReferenceError: React is not defined"
Found similar results with @material-ui/icons
using
import AccessAlarmIcon from '@material-ui/icons/AccessAlarm'
200726 B
154712 B "TypeError: (0 , Oj.default) is not a function"
It freezes up when using a named import
import { AccessAlarm } from '@material-ui/icons'
P.S. Couldn't test with ESM, as the library no longer provides them.