Laravel-mix: Class static properties are not supported

Created on 13 Dec 2017  路  4Comments  路  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: 1.7.2
  • Node Version: 8.9.0
  • NPM Version: 5.6.0
  • OS: MacOS High Sierra

Description & Steps:

Trying to compile some JS which contains something like:

class MyClass extends Component {
  static PropTypes = {
    ...
  }
}

When transpiling it throws an error for an unexpected token at the equal sign.

I was hoping this was resolved in #971, so I updated to 1.7.2, but no dice.

I admittedly don't know enough about which version of ESCMA needs to be supported in order for this to work. Does Laravel Mix somewhere document which version it supports?

It would be great to have static methods and properties supported!

Most helpful comment

I installed it with Babel
npm install --save-dev babel-plugin-transform-class-properties
Then, create a .babelrc in the root of your project

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

All 4 comments

I installed it with Babel
npm install --save-dev babel-plugin-transform-class-properties
Then, create a .babelrc in the root of your project

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

Thanks, @helmerdavila! So Laravel Mix will automatically take that into account?

I'm familiar with Babel, but haven't used it, yet. Is it reliable to do things like that?

Maybe in the future this will be included by default

Class properties are an experimental feature of js in the draft phase. At some point in the future, it may become a js feature. Until then you'll need to pull in the plugin.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stefensuhat picture stefensuhat  路  3Comments

jpmurray picture jpmurray  路  3Comments

Bomavi picture Bomavi  路  3Comments

Micaso picture Micaso  路  3Comments

jpriceonline picture jpriceonline  路  3Comments