Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equal sign in bad place causes unknown token exception

I'm upgrading a react babel 5 project to babel 6. The code is from pluralsight on github. The error occurs on app.js. I assume there is a plugin that needs an upgrade that allows this syntax to work:

export default class DriftApp extends React.Component {
  state = {//builder is not happy with this equals sign, unexpected token
    showIndex: 0,
    numSlides: 5
  }

Which plugin does this?

Here's my package.json:

 "homepage": "https://github.com/jaketrent/react-drift#readme",
  "devDependencies": {
    "autobind-decorator": "^1.3.3",
    "babel-core": "^6.5.1",
    "babel-loader": "^6.2.2",
    "babel-plugin-react-transform": "^2.0.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-preset-es2015": "^6.5.0",
    "babel-preset-react": "^6.5.0",
    "express": "^4.13.3",
    "file-loader": "^0.8.4",
    "radium": "^0.16.6",
    "react": "^0.14.2",
    "react-dom": "^0.14.2",
    "react-hot-loader": "^2.0.0-alpha-4",
    "react-tools": "^0.10.0",
    "react-transform": "0.0.3",
    "react-transform-catch-errors": "^1.0.0",
    "react-transform-hmr": "^1.0.1",
    "redbox-react": "^1.1.1",
    "webpack": "^1.12.2",
    "webpack-dev-middleware": "^1.2.0",
    "webpack-hot-middleware": "^2.4.1"
  }
}
like image 945
P.Brian.Mackey Avatar asked Dec 19 '22 19:12

P.Brian.Mackey


1 Answers

You are using property initializers syntax in your code, which is an experimental feature (proposal). You can transpile this to ES5 by installing the babel-plugin-transform-class-properties module

npm install babel-plugin-transform-class-properties  --save-dev

Add the following line to your .babelrc file:

{
  "plugins": ["transform-class-properties"]
}

ref https://babeljs.io/docs/plugins/transform-class-properties/

like image 90
Darshan Avatar answered Dec 31 '22 01:12

Darshan