Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

enter image description here

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"
  }
}
like image 558
vijay Avatar asked Aug 21 '17 11:08

vijay


1 Answers

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"
    ]
}
like image 145
Erazihel Avatar answered Nov 20 '22 17:11

Erazihel