简体   繁体   English

将“proposal-object-rest-spread”插件添加到 babel.config.js 以修复 Microsoft Edge 错误 SCRIPT1028

[英]Add “proposal-object-rest-spread” plugin to babel.config.js to fix Microsoft Edge error SCRIPT1028

EDIT: This issue seems to be fixed with the new beta of Microsoft Edge Chromium.编辑:此问题似乎已通过 Microsoft Edge Chromium 的新测试版修复。 (January 18, 2020) (2020 年 1 月 18 日)

I need to add this Babel plugin to babel.config.js to get rid of the Microsoft Edge Browser error我需要将此Babel 插件添加到babel.config.js以摆脱 Microsoft Edge浏览器错误

SCRIPT1028: Expected identifier, string or number SCRIPT1028:预期的标识符、字符串或数字

I installed the latest packages and added them to package.json.我安装了最新的软件包并将它们添加到 package.json。 Below is what I tried but it doesn't transform the code after running npm run build :以下是我尝试过的,但在运行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"
  ]
}

How to setup the Babel plugin to transform the code correctly?如何设置 Babel 插件以正确转换代码?

EDIT: Error Screenshot - EDGE INSIDER 18 points to this piece of code:编辑:错误截图 - EDGE INSIDER 18 指向这段代码: 错误:EDGE INSIDER 18 指向这段代码。

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:由于我无法尝试您要检查的代码,我建议使用库配置中提到的以下 babel 配置:

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

babel.config.js should export a function and should be at the root of your project. babel.config.js应该导出function并且应该在项目的根目录下。

Your configuration should be similar to this您的配置应该与此类似

module.exports = function(api) {
    api.cache(true);

    const presets = ['@vue/app'];
    const plugins = ['@babel/plugin-proposal-object-rest-spread'];
    // Or try this
    // const plugins = [['@babel/plugin-proposal-object-rest-spread', { loose: true, useBuiltIns: true }]];

    return {
        presets,
        plugins,
    };
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 babel.config.js:加载配置时出错 - 找不到模块“纤维” - babel.config.js: Error while loading config - Cannot find module 'fibers' 无法使用babel-plugin-transform-object-rest-spread为vue cli 3设置传播对象 - Not able to spread an object with babel-plugin-transform-object-rest-spread added for vue cli 3 setup @babel/plugin-proposal-optional-chaining 在 Vue.js 中不起作用<script> tag - @babel/plugin-proposal-optional-chaining not working inside Vue.js <script> tag 安装ES2018对象传播算子babel插件错误 - Installing the ES2018 object spread operator babel plugin error babel.config.js 和 vue.config.js 有什么区别,我可以合并这两个文件吗? - what is the difference between babel.config.js and vue.config.js and can i combine the 2 files? Webpack&Babel-Loader - 对象休息运算符上的意外令牌,安装了transform-object-rest-spread插件 - Webpack & Babel-Loader - Unexpected Token on Object Rest Operator, with transform-object-rest-spread Plugin Installed 配置Webpack,Node和Babel对象rest spread变换 - Configure Webpack, Node, and the Babel object rest spread transform 为什么 babel-loader 不转换 object 休息/传播? - Why is babel-loader not transforming object rest/spread? 如何让 @babel/plugin-proposal-private-methods 在 vue.js webpack 模板中工作? - How to make @babel/plugin-proposal-private-methods work in the vue.js webpack template? vuejs 使用 babel plugin-proposal-class-properties - vuejs use babel plugin-proposal-class-properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM