vue 项目打包后 IE11 报告 SCRIPT5009: “Promise”未定义

Vanghohs
  • 183

开发环境正常,且开发环境没有配置 babel-polyfill。
也就是说开发环境下ie11 可以打开页面(开发环境没有配置babel-polyfill也能用ie11打开)。
但是打包部署后就不行了 -_-。

为此,增加了babel-plyfill, 但是并没有解决问题呀。。。

package.json:

{
  "name": "edongmi-app",
  "version": "2.1.1",
  "description": "edongmi saas system",
  "author": "www.simubb.com",
  "private": true,
  "scripts": {
    "dev": "node build/dev-server.js",
    "start": "node build/dev-server.js",
    "build": "node build/build.js",
    "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
    "e2e": "node test/e2e/runner.js",
    "test": "npm run unit && npm run e2e",
    "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
  },
  "dependencies": {
    "axios": "^0.16.2",
    "babel-polyfill": "^6.26.0",
    "chart.js": "2.5.0",
    "element-theme-default": "^1.4.12",
    "element-ui": "^2.0.10",
    "es6-promise": "^4.2.2",
    "vue-chartjs": "2.6.3",
    "vue-router": "2.5.3",
    "vue-strap": "github:wffranco/vue-strap",
    "vue-template-compiler": "^2.5.3",
    "vuex": "^2.3.1"
  },
  "devDependencies": {
    "autoprefixer": "7.1.1",
    "babel-core": "6.24.1",
    "babel-eslint": "7.2.3",
    "babel-loader": "7.0.0",
    "babel-plugin-istanbul": "4.1.3",
    "babel-plugin-transform-runtime": "^6.22.0",
    "babel-preset-env": "1.5.1",
    "babel-preset-stage-2": "6.24.1",
    "babel-register": "6.24.1",
    "chai": "^3.5.0",
    "chalk": "^1.1.3",
    "chromedriver": "^2.29.0",
    "connect-history-api-fallback": "^1.3.0",
    "copy-webpack-plugin": "^4.0.1",
    "cross-env": "5.0.0",
    "cross-spawn": "^5.0.1",
    "css-loader": "0.28.2",
    "eslint": "3.19.0",
    "eslint-config-standard": "10.2.1",
    "eslint-friendly-formatter": "3.0.0",
    "eslint-loader": "1.7.1",
    "eslint-plugin-html": "2.0.3",
    "eslint-plugin-import": "2.2.0",
    "eslint-plugin-node": "4.2.2",
    "eslint-plugin-promise": "3.5.0",
    "eslint-plugin-standard": "3.0.1",
    "eventsource-polyfill": "^0.9.6",
    "express": "4.15.3",
    "extract-text-webpack-plugin": "2.1.0",
    "file-loader": "0.11.1",
    "friendly-errors-webpack-plugin": "1.6.1",
    "html-webpack-plugin": "^2.28.0",
    "http-proxy-middleware": "0.17.4",
    "inject-loader": "3.0.0",
    "karma": "1.7.0",
    "karma-coverage": "^1.1.1",
    "karma-mocha": "^1.3.0",
    "karma-phantomjs-launcher": "1.0.4",
    "karma-phantomjs-shim": "^1.4.0",
    "karma-sinon-chai": "1.3.1",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-spec-reporter": "0.0.31",
    "karma-webpack": "2.0.3",
    "lolex": "^1.5.2",
    "mocha": "3.4.1",
    "nightwatch": "0.9.15",
    "opn": "5.0.0",
    "optimize-css-assets-webpack-plugin": "1.3.2",
    "ora": "1.2.0",
    "phantomjs-prebuilt": "^2.1.14",
    "rimraf": "^2.6.0",
    "selenium-server": "3.4.0",
    "semver": "^5.3.0",
    "shelljs": "^0.7.6",
    "sinon": "2.3.1",
    "sinon-chai": "2.10.0",
    "url-loader": "^0.5.7",
    "vue-loader": "12.1.0",
    "vue-style-loader": "3.0.1",
    "webpack": "2.6.0",
    "webpack-bundle-analyzer": "2.8.2",
    "webpack-dev-middleware": "1.10.2",
    "webpack-hot-middleware": "2.18.0",
    "webpack-merge": "4.1.0"
  },
  "engines": {
    "node": ">= 4.0.0",
    "npm": ">= 3.0.0"
  }
}

main.js 第一行引入了

import 'babel-polyfill'
回复
阅读 4.9k
4 个回答

要在webpack的入口文件里加上babel-polyfill

entry: {

app: "./src/main.js"

}
改为
entry: {

app: ["babel-polyfill", "./src/main.js"]

}
main 不要import 了

Tracy_Sun
  • 3
新手上路,请多包涵

果然去掉main里面的就行了

和咸鱼没有区别
  • 1
新手上路,请多包涵

我使用的是react,只需要操作两个步骤,
一个是在dependencies 中增加上"babel-polyfill": "^6.26.0";
一个是在引入的每个模块后面,都加上相同的 模块名:["babel-polyfill",'模块的js']
图片描述

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏