添加“提案对象剩余传播" babel.config.js的插件以修复Microsoft Edge错误SCRIPT1028 [英] Add "proposal-object-rest-spread" plugin to babel.config.js to fix Microsoft Edge error SCRIPT1028

查看:926
本文介绍了添加“提案对象剩余传播" babel.config.js的插件以修复Microsoft Edge错误SCRIPT1028的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Microsoft Edge Chromium的新Beta版似乎已解决此问题. (2020年1月18日)

我需要添加 Babel插件 babel.config.js 摆脱Microsoft Edge 浏览器错误

I need to add this Babel plugin to babel.config.js to get rid of the Microsoft Edge Browser error

SCRIPT1028:期望的标识符,字符串或数字

SCRIPT1028: Expected identifier, string or number

我安装了最新的软件包并将其添加到package.json. 以下是我尝试过的操作,但在运行 npm run build 后不会转换代码:

I installed the latest packages and added them to package.json. Below is what I tried but it doesn't transform the code after running npm run build:

babel.config.js

babel.config.js

require("@babel/core").transform("code", {});

module.exports = {
  presets: ["@vue/app"],
  plugins: ["@babel/plugin-proposal-object-rest-spread"]
};

package.json

package.json

{
  "name": "example",
  "version": "0.2.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "@babel/polyfill": "^7.6.0",
    "core-js": "^2.6.5",
    "date-fns": "^2.4.1",
    "firebase": "^7.0.0",
    "lodash": "^4.17.15",
    "register-service-worker": "^1.6.2",
    "vue": "^2.6.10",
    "vue-flickity": "^1.2.1",
    "vue-router": "^3.0.3",
    "vuetify": "^2.0.0",
    "vuex": "^3.0.1"
  },
  "devDependencies": {
    "@babel/cli": "^7.6.4",
    "@babel/core": "^7.6.4",
    "@babel/plugin-proposal-object-rest-spread": "^7.6.2",
    "@babel/preset-env": "^7.6.3",
    "@vue/cli-plugin-babel": "^3.11.0",
    "@vue/cli-plugin-eslint": "^3.11.0",
    "@vue/cli-plugin-pwa": "^3.11.0",
    "@vue/cli-service": "^3.11.0",
    "@vue/eslint-config-prettier": "^5.0.0",
    "babel-eslint": "^10.0.1",
    "eslint": "^5.16.0",
    "eslint-plugin-prettier": "^3.1.0",
    "eslint-plugin-vue": "^5.0.0",
    "material-design-icons-iconfont": "^5.0.1",
    "prettier": "^1.18.2",
    "sass": "^1.17.4",
    "sass-loader": "^7.1.0",
    "stylus": "^0.54.5",
    "stylus-loader": "^3.0.2",
    "terser-webpack-plugin": "^2.1.2",
    "uglifyjs-webpack-plugin": "^2.2.0",
    "vue-cli-plugin-vuetify": "^0.6.3",
    "vue-template-compiler": "^2.6.10",
    "vuetify-loader": "^1.2.2"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "@vue/prettier"
    ],
    "rules": {},
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },
  "postcss": {
    "plugins": {
      "autoprefixer": {}
    }
  },
  "browserslist": [
    "> 1%",
    "last 2 versions"
  ]
}

如何设置Babel插件以正确转换代码?

How to setup the Babel plugin to transform the code correctly?

错误截图-EDGE INSIDER 18指向这段代码:

Error Screenshot - EDGE INSIDER 18 points to this piece of code:

推荐答案

由于我无法尝试处理要检查的代码,因此建议使用库配置中提到的以下babel配置:

since I cannot try out the code that you are dealing with to check, I would suggest to use the following babel config as mentioned in the library config:

  plugins: [["@babel/plugin-proposal-object-rest-spread", { "loose": true, "useBuiltIns": true }]]

这篇关于添加“提案对象剩余传播" babel.config.js的插件以修复Microsoft Edge错误SCRIPT1028的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆