为什么 webpack 不喜欢 React.StrictMode

Why does webpack not like React.StrictMode

当我 运行 npx webpack-cli --analyze --node-env development 我得到一个关于它不喜欢的错误 <React.StrictMode>:

Webpack Bundle Analyzer is started at http://127.0.0.1:8888
Use Ctrl+C to close it
Hash: 24852f2f5b5cef02cfe2
Version: webpack 4.42.0
Time: 57ms
Built at: 08/11/2021 2:53:12 PM
  Asset      Size  Chunks             Chunk Names
main.js  4.09 KiB    main  [emitted]  main
Entrypoint main = main.js
[./src/index.js] 316 bytes {main} [built] [failed] [1 error]

ERROR in ./src/index.js 9:2
Module parse failed: Unexpected token (9:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|
| ReactDOM.render(
>   <React.StrictMode>
|     <App />
|   </React.StrictMode>,

我正在使用 .\node_modules\react-scripts\config\webpack.config.js 中的默认配置。为什么 webpack 不喜欢 React.StrictMode?

我找到了答案,只需使用 source-map-explorer 即可:

"scripts": {
    "start": "rimraf ./build && react-scripts start",
    "build": "react-scripts build",
    "analyze": "source-map-explorer 'build/static/js/*.js'",
    "test": "cross-env CI=true react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "lint": "eslint ./src/"
  },