【发布时间】:2020-11-24 20:10:03
【问题描述】:
由于Object doesn't support property or method 'endsWith' 错误,我的网站中断并无法运行。我试过用import 'core-js/features/string/ends-with' 或
if (!String.prototype.endsWith) {
String.prototype.endsWith = function (search, this_len) {
if (this_len === undefined || this_len > this.length) {
this_len = this.length
}
return this.substring(this_len - search.length, this_len) === search
}
}
我已经在我的自定义_app 文件中做到了这一点,但它在 edge 和 ie11 中仍然失败。我错过了什么?
编辑:根据https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith#Browser_compatibility 判断,Edge 应该支持endsWith
【问题讨论】:
-
当您在 Next.js 项目中使用外部 npm 模块时,您必须手动为它们添加 polyfill。添加polyfills后,您可以参考this post关于IE 11中Next Js的解决方案。
标签: reactjs next.js microsoft-edge polyfills