簡體   English   中英

將 Webpack 從 v4 遷移到 v5 后,我的 React 應用程序未在 IE11 中運行

[英]My react app not running in IE11 after migrated Webpack from v4 to v5

我按照 webpack 文檔更改了我的應用程序的配置: https ://webpack.js.org/migrate/5/。 此后,該應用程序在 chrome 和 edge 上成功運行,但在 IE11 中無法運行。 在此處輸入圖片說明

我有一個 .browserslistrc 文件,里面有 IE11,也改變了target: ['web', 'es5'] ,然后添加import 'react-app-polyfill/ie11'; import 'react-app-polyfill/stable'; import 'react-app-polyfill/ie11'; import 'react-app-polyfill/stable'; 到 src/index.js 但問題仍然存在。 我使用以下 babel 配置:

  "presets": [
    [
      "@babel/preset-env", 
      { 
        "useBuiltIns": "entry",
        "corejs": 3
      }
    ],
    "@babel/preset-react"
  ],
  "plugins": [
    "@babel/plugin-transform-object-assign", 
    "@babel/plugin-proposal-object-rest-spread", 
    "@babel/plugin-transform-regenerator", 
    "@babel/plugin-proposal-class-properties", 
    "@babel/plugin-transform-runtime"
  ]
}

經過大量調查,我發現了這一點:

https://github.com/feross/buffer/commit/840160f352ff0d8e88d4ac308a1640fd278f50fc

所以我的問題的解決方案是配置 babel-loader 來轉譯這個包:

{
    test: /\.js$/,
    include: [
       path.join(__dirname, 'src'),
       path.join(__dirname, 'node_modules/buffer'),
    ],
    loader: 'babel-loader',
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM