对象不支持“ for”属性或方法

时间:2019-08-04 16:40:46

标签: javascript reactjs internet-explorer webpack next.js

我正在将Next JS用于我的一个项目,并且在Internet Explorer 11中遇到错误:

  

对象不支持'for'属性或方法

该错误似乎起源于commonswebpack文件,请参见下面的堆栈,其中网站被屏蔽:

enter image description here

在查看了文件中的.for方法后,似乎是捆绑代码中使用的一些符号。

我尝试像这样在我的webpack配置中导入core-js polyfils:

import 'core-js/features/symbol';

但这会引发以下错误:

  

未捕获到错误TypeError:预期对象

我尝试了另一种方法-在我的应用<head>中包括polyfil:

<script src='https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.23.0/polyfill.min.js' />

并再次尝试在ie中运行时收到以下错误:

  

未捕获到错误SecurityError

我上面尝试的两种方法(使用core-js导入并包括babel-polyfil库)似乎都为dom提供了Symbol.for方法。 IE,如果我在添加任何一个polyfil之前键入Symbol.for都会得到未定义的结果,并在返回后返回一个函数,所以我不太确定为什么它仍然会失败。

最后,如果有什么帮助,这是我的下一个配置,但我认为这不是导致它的原因:

require('dotenv').config()
const webpack = require('webpack')
const withSass = require('@zeit/next-sass');
const withFonts = require('next-fonts');

module.exports =
    withFonts(withSass({
        webpack: (config, {
            dev
        }) => {

            // Fixes npm packages that depend on `fs` module
            config.node = {
                fs: 'empty'
            }
            config.plugins.push(new webpack.EnvironmentPlugin(process.env))

            if (dev) {
                config.devtool = 'cheap-module-source-map';
            }

            config.module.rules.push({
                test: /\.(png|svg)$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: 100000,
                        publicPath: './',
                        outputPath: 'static/',
                        name: '[name].[ext]'
                    }
                }
            })

            const originalEntry = config.entry
            config.entry = async () => {
                const entries = await originalEntry()

                if (
                    entries['main.js'] &&
                    !entries['main.js'].includes('./client/polyfills.js')
                ) {
                    entries['main.js'].unshift('./client/polyfills.js')
                }

                return entries
            }

            return config

        }
    }))

0 个答案:

没有答案
相关问题