未在IE11上加载错误“符号”的Vue.js未定义

时间:2016-12-16 13:40:45

标签: javascript webpack vue.js

在我的webapp上使用Vue.js可以在除IE11之外的大多数浏览器上运行。我尝试了默认babel-preset-es2015,也尝试了babel-preset-es2015-ie,但没有运气:代码仍然没有在IE11上运行 '符号'未定义 错误。

.babelrc

{
  "presets": ["es2015"]  << also tried es2015-ie
}

的package.json

  "scripts": {
    "dev": "cross-env NODE_ENV=development webpack-dev-server --inline --hot --port 3000 --host 0.0.0.0",
    "build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
  },
  "dependencies": {
    "bootstrap-loader": "^1.3.2",
    "jquery": "^3.1.1",
    "less": "^2.7.1",
    "less-loader": "^2.2.3",
    "vue": "^2.1.6"
  },
  "devDependencies": {
    "babel-core": "^6.20.0",
    "babel-loader": "^6.2.10",
    "babel-preset-es2015": "^6.18.0",
    "bootstrap-sass": "^3.3.7",
    "cross-env": "^1.0.6",
    "css-loader": "^0.23.1",
    "exports-loader": "^0.6.3",
    "extract-text-webpack-plugin": "^1.0.1",
    "file-loader": "^0.8.5",
    "imports-loader": "^0.7.0",
    "json-loader": "^0.5.4",
    "node-sass": "^4.0.0",
    "resolve-url-loader": "^1.6.1",
    "sass-loader": "^4.1.0",
    "style-loader": "^0.13.1",
    "url-loader": "^0.5.7",
    "vue-loader": "^9.8.0",
    "webpack": "^1.14.0",
    "webpack-dev-server": "^1.16.2"
  }

2 个答案:

答案 0 :(得分:6)

正如@Leonid指出的那样,我缺少浏览器 - 填充脚本,如this answer所述。现在在IE11(和其他浏览器)上工作正常。

这是我做的:

npm install --save-dev babel-polyfill

<强> webpack.config.js

module.exports = {
  entry: ['babel-polyfill', './src/main.js'],
  ....
  ....
}

答案 1 :(得分:0)

我宁愿先更新webpack.mix.js。然后使用@babel/polyfillbabel-loader的更新版本。而这些@ babel / core babel预设不是必需的。 corejs 3是较新的版本,但似乎无法解决。请任何人知道如何使导入core-js / stable正常工作!

使用NPM:

npm install babel-loader @babel/polyfill --save

webpack.mix.js

module: {
      rules: [{
          test: /\.js?$/,
          exclude: /(bower_components)/,
          use: [{
              loader: 'babel-loader',
              options: mix.config.babel()
          }]
      }]
  }

最后在您的main / js或app.js文件的开头导入@ babel / polyfill

import '@babel/polyfill';

依赖项:

"@babel/polyfill": "^7.10.4",
"babel-loader": "^8.1.0",
"vue": "^2.6.11",