【问题标题】:Using Set polyfill in webpack doesn't resolve errors在 webpack 中使用 Set polyfill 不能解决错误
【发布时间】:2018-05-31 18:56:05
【问题描述】:

我在旧版浏览器的生产环境中看到一些“找不到变量:设置”错误。我认为这是 Typescript 和 Webpack 对 es6 功能的使用雄心勃勃,没什么大不了的,我可以填充它,就像我为 React 填充 Object.assign 一样。

现在我的 webpack 的 Polyfill 配置如下所示:

// using include in the callback selection requires a polyfill for ie
require('string.prototype.includes');

// some older browsers don't support Set, which apparently something compiles to
require('es6-set');

// fetch() polyfill for making API calls.
require('whatwg-fetch');

// Object.assign() is commonly used with React.
// It will use the native implementation if it's present and isn't buggy.
Object.assign = require('object-assign');

但在发布并验证发布后,我仍然在旧浏览器中看到与 Set 相关的错误。我查看了将 polyfills 添加到 webpack 的文档,但我不知道我是否缺少步骤或为什么这不起作用。

我做错了什么,或者我还能尝试什么?

【问题讨论】:

  • 我认为使用 core-js 是 polyfills 的标准,但看起来你正在使用 github.com/medikoo/es6-set 。如果您查看自述文件,它会说“如果您想确保您的环境实现 Set,请执行:require('es6-set/implement');。如果您想在本地版本存在时使用它,如果不存在则回退到 polyfill,但是如果不在全局范围内实现 Set,请执行:var Set = require('es6-set');"。所以听起来你应该使用require('es6-set/implement');,如果你只想全局设置一次而不是管理每次使用。
  • @matmo 也许这是 es6-set 特有的,而不是通常的工作方式?我尝试从core-js 发送套装,让我们看看是否可行。

标签: typescript webpack polyfills


【解决方案1】:

你的代码:

// some older browsers don't support Set, which apparently something compiles to
require('es6-set');

不遵循项目的自述文件:https://www.npmjs.com/package/es6-set

修复

来自自述文件:

require('es6-set/implement');

【讨论】:

    猜你喜欢
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-07
    • 1970-01-01
    • 2018-02-15
    相关资源
    最近更新 更多