babel-preset-env SyntaxError: Unexpected token with spread properties

谁说我不能喝 提交于 2019-11-30 05:02:57

问题


Why its not accepting spread properties ? I am using babel-preset-env for this.

.babelrc

{
    "presets": [
        "react",
        [
            "env",
            {
                "targets": {},
                "debug": true,
                "modules": "commonjs"
            }
        ]
    ]
}

package.json

{
  "name": "myapp",
  "version": "0.1.0",
  "main": "index.js",
  "private": true,
  "dependencies": {
    "babel-core": "6.25.0",
    "babel-loader": "7.1.1",
    "babel-preset-env": "^1.6.0",
    "babel-preset-react": "^6.24.1",
    "extract-text-webpack-plugin": "3.0.0",
    "file-loader": "0.11.2",
    "html-webpack-plugin": "^2.30.1",
    "moment": "^2.18.1",
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-router": "^4.1.2",
    "react-router-dom": "^4.1.2",
    "redux": "^3.7.2",
    "redux-form": "^7.0.3",
    "style-loader": "0.18.2",
    "url-loader": "0.5.9",
    "webpack": "3.5.1",
    "webpack-dev-server": "2.7.1",
    "webpack-node-externals": "^1.6.0"
  },
  "scripts": {
    "start": "",
    "build": "webpack"
  }
}

回答1:


The Object rest spread operator will probably be a future feature of an ECMAScript specification (it's in stage 3 for the moment).

For now, it can be supported thanks to Babel but you have to use the transform-object-rest-spread plugin.

{
    "presets": [
        "react",
        [
            "env",
            {
                "targets": {},
                "debug": true,
                "modules": "commonjs"
            }
        ],
        "transform-object-rest-spread"
    ]
}


来源:https://stackoverflow.com/questions/45796082/babel-preset-env-syntaxerror-unexpected-token-with-spread-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!