babel / babelify

Browserify transform for Babel
MIT License
1.68k stars 114 forks source link

Getting an error with static properties #167

Closed shaimo closed 8 years ago

shaimo commented 8 years ago

I'm using browserify-rails with babelify and trying to compile e.g. the code here: https://facebook.github.io/relay/docs/guides-mutations.html#content Getting an error on the static property:

SyntaxError: /Users/shaimo-mbp/dev/ruby/myapp/app/assets/javascripts/components/TestComponent.js.jsx: Unexpected token (7:21)
   5 | 
   6 | class LikeStoryMutation extends Relay.Mutation {
>  7 |     static fragments = {
     |                      ^
   8 |          story: () => Relay.QL`
   9 |           fragment on Story {
  10 |             id,

My command line looks like:

    config.browserify_rails.commandline_options = '--extension=.js --extension=.js.jsx -t [ babelify --presets [ es2015 react ] --plugins ./utils/babelRelayPlugin ]'

(I tried also without one or two of the presets and also with reactify)... Is this some bug or am I doing anything wrong?

loganfsmyth commented 8 years ago

You are using es2015 and react and neither of those support class properties, which are not standard ES6. Standard ES6 classes can only have methods, not properties. Class properties are enabled with http://babeljs.io/docs/plugins/transform-class-properties/ so you'd need to use the plugin directly or babel-preset-stage-1 or babel-preset-stage-0

shaimo commented 8 years ago

Thank you! :+1:

kopax commented 4 years ago

Hello, Is that still the case 4 years after? https://stackoverflow.com/questions/59617327/what-is-the-appropriate-webpack-loader-to-use-static-keywords

goto-bus-stop commented 4 years ago

@kopax i think that's most likely a webpack loader misconfiguration. this issue is for babelify, which is the loader for browserify, not for webpack.

static fields are still a Stage 3 proposal and have not yet landed in ES, so you need to configure both babel-loader and the appropriate babel transform.