【问题标题】:fetch and Headers are undefined in IE11.0.9600 with babel-polyfill when process.env.NODE_ENV=='production'当 process.env.NODE_ENV=='production' 时,使用 babel-polyfill 在 IE11.0.9600 中未定义 fetch 和 Headers
【发布时间】:2017-11-23 11:05:41
【问题描述】:

当process.env.NODE_ENV=='development' - 没关系!

但我们的生产构建在 IE 11 (11.0.9600) 中失败。 在 chrome 55 中一切正常。

开发依赖:

...
babel-core: "6.22.0",
babel-eslint: "^7.0.0",
babel-loader: "^6.2.5",
babel-preset-env: "^1.5.2",
babel-preset-es2015: "^6.16.0",
babel-preset-es2016: "^6.22.0",
babel-preset-es2017: "^6.16.0",
babel-preset-react: "^6.16.0",
babel-preset-stage-0: "^6.22.0"
...

依赖:

...
babel-polyfill: "^6.16.0"
...

.babelrc:

{
    "presets": [
        "react",
        ["env", {
             "useBuiltIns": true
        }],
        "stage-0"
    ]
}

尝试"useBuiltIns": false、es2016、es2015、es2017 预设。没有任何变化。

index.js:

"use strict";
import 'babel-polyfill'
...

webpack.config 模块.exports.entry:

vendor: ['babel-polyfill', 'immutable', 'react', 'react-dom', ...],
...
bundle: [path.resolve(__dirname, srcPath + ""index.js)]

vendor 是 index.html 中的第一个脚本。

在控制台中输入_babelPolyfill 返回true。 但是 Headers, fetch 是未定义的...

为什么process.env.NODE_ENV=='production' 在 IE11 中破坏了我的应用程序? 如何修复我的配置?

【问题讨论】:

    标签: javascript internet-explorer babeljs fetch-api babel-polyfill


    【解决方案1】:

    core.js 没有用于 Headers() 和 fetch 的 polyfill,所以 babel-polyfill 没有。 使用 fetch polyfill 之一:

    • whatwg-fetch polyfill 仅支持浏览器https://github.com/github/fetch
    • isomorphic-fetch - polyfill,基于 whatwg-fetch,用于节点和浏览器支持

    更多信息:

    https://github.com/zloirock/core-js

    What is the difference between isomorphic-fetch and fetch?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-06
      • 2021-11-04
      • 1970-01-01
      • 2015-10-09
      • 2022-01-05
      • 2017-01-24
      • 1970-01-01
      • 2022-07-22
      相关资源
      最近更新 更多