运行webpack时IE11错误

时间:2018-08-29 11:38:27

标签: vue.js webpack

我正在开发VueJS应用程序,但在IE11中无法正常工作。我得到空白页,并且在此行上显示“无法获取未定义或空引用的属性'调用'”错误:

// Return the exports of the module return module.exports;

我的webpack.base.config.js文件:

```module.exports = {
  entry: ['babel-polyfill', './src/main.js'],
  context: path.resolve(__dirname, '../'),
  output: {
    path: config.build.assetsRoot,
    filename: '[name].js',
    publicPath: process.env.NODE_ENV === 'production'
    ? config.build.assetsPublicPath
    : config.dev.assetsPublicPath
  },
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
    }
  },
  module: {
    rules: [
      ...(config.dev.useEslint ? [createLintingRule()] : []),
      {
        test: /\.scss$/,
        use: [
          'vue-style-loader',
          'css-loader',
          'sass-loader'
        ]
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: vueLoaderConfig
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('img/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('media/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
        }
      }
    ]
  },```

我的package.json(为简便起见,简称

```
"dependencies": {
    "@babel/polyfill": "^7.0.0",
    "axios": "^0.18.0",
    "babel-polyfill": "^6.26.0",
    "basscss": "^8.0.2",
    "es6-promise": "^4.2.4",
    "jquery": "^3.3.1",
    "vue": "^2.5.2",
    "vue-i18n": "^8.0.0",
    "vue-router": "^3.0.1",
    "vue-scrollto": "^2.11.0",
    "vuelidate": "^0.7.4"
  },
  "devDependencies": {
    "@kazupon/vue-i18n-loader": "^0.3.0",
    "autoprefixer": "^7.1.2",
    "babel-core": "^6.22.1",
    "babel-eslint": "^8.2.1",
    "babel-helper-vue-jsx-merge-props": "^2.0.3",
    "babel-loader": "^7.1.1",
    "babel-plugin-syntax-jsx": "^6.18.0",
    "babel-plugin-transform-runtime": "^6.22.0",
    "babel-plugin-transform-vue-jsx": "^3.5.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-2": "^6.22.0"
}```

有人可以帮忙吗?几天来一直试图解决这个问题...

4 个答案:

答案 0 :(得分:1)

我无法解决它,所以我从头开始设置了项目,并使其在IE中正常工作,除了一些滚动功能。发布此消息,因为它可能会帮助其他人。

使用vue-cli设置新项目(在IE中有效) https://cli.vuejs.org/guide/installation.html

然后从原始项目复制的main.js导入到新的main.js文件。根据需要安装依赖项。

这时我出现了一个错误,说:

You are using the runtime-only build of Vue where the template compiler is not available.
Either pre-compile the templates into render functions, or use the compiler-included build.

阅读一些文档,然后在main.js文件中,我替换了

new Vue({
  el: '#app',
  i18n,
  components: { App },
  template: '<App/>'
})

使用

new Vue({
  i18n,
  render: h => h(App)
}).$mount('#app')

然后Sass文件不起作用:需要安装sass-loader

npm install sass-loader node-sass webpack --save-dev

现在我的SCSS文件正在编译。

在main.js中导入https://www.npmjs.com/package/vue-scrollto(用于滚动功能)时,IE中断。暂时不在我的应用程序中,但是该应用程序现在可以在IE中使用。

答案 1 :(得分:0)

我有一个类似的问题,可以通过安装polyfill来解决 https://www.npmjs.com/package/promise-polyfill

npm install promise-polyfill --save-exact

希望有帮助,IE总是很痛苦

答案 2 :(得分:0)

https://babeljs.io/docs/en/babel-polyfill.html

尝试安装该插件,并按照说明在webpack和main.js中调用polyfill的步骤进行操作

npm install --save @babel/polyfill

答案 3 :(得分:0)

尝试添加导入“ promise-polyfill / src / polyfill”;到main.js文件