gpt4 book ai didi

javascript - 当 process.env.NODE_ENV= ='production' 时,使用 babel-polyfill 在 IE11.0.9600 中未定义 fetch 和 Headers

转载 作者:数据小太阳 更新时间:2023-10-29 05:21:26 24 4
gpt4 key购买 nike

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 module.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 中破坏了我的应用程序?如何修复我的配置?

最佳答案

core.js 没有用于 Headers() 和 fetch 的 polyfill,所以 babel-polyfill 没有。使用其中一种获取 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?

关于javascript - 当 process.env.NODE_ENV= ='production' 时,使用 babel-polyfill 在 IE11.0.9600 中未定义 fetch 和 Headers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44660928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com