mobx: Decorators are not supported yet in 6.x pending proposal update.
Just tried mobservable in my project, though ran into this issue:
Module build failed: SyntaxError:
Decorators are not supported yet in 6.x pending proposal update.
20 |
21 | @observer
> 22 | class TimerView extends Component {
| ^
23 | render() {
24 | return (
25 | <button onClick={this.onReset}>
Here is my .babelrc:
{
"presets": [
"react",
"es2015",
"stage-1"
],
"env": {
"development": {
"presets": [
"react-hmre"
]
}
}
}
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 30 (10 by maintainers)
Commits related to this issue
- Updated tests to use babel6, see #105 — committed to mobxjs/mobx by mweststrate 8 years ago
found the solution:
As reported here: https://github.com/mobxjs/mobx-react/issues/41 it appears that the order of plugins is important, make sure that
transform-decorators-legacyappears first!My solution was .babelrc
webpack.config.js
So added
"plugins": ["transform-decorators-legacy"]to both filesInstall
npm i --save-dev babel-plugin-transform-decorators-legacy. Update thepackage.json(I usecreat-react-appand I have ejected):@mweststrate, Thanks mate, I’ll give a try. Thumbs up for the really good work.
@DigitalMarc ah! check: https://github.com/zeit/next.js/issues/26. Edit: see you already found it. Yeah I think the issue is probably that the plugins don’t get the right priority. If it is just for testing / play, you might try to modify the babelrc of next itself in your node_modules (or by creating a fork), that should give some clue whether this is indeed the issue
You need babel-plugin-transform-class-properties
Hey guys, i got a problem about mobx envirnoment. I have .babelrc file like this
And i intall babel-preset and babel-plugin which is needed. After test, i could use decorator in my project. But when it comes to mobx use like
I got output
SyntaxError: index.js: Unexpected tokenat timer = 0, what should i do to fix it? I have knowed that decorator should work with class/function, Any extra configuration is needed whe n i want to create observable properties?Hi guys, Within this config:
For this bit of code:
I got this output:
Method has decorators, put the decorator plugin before the classes one.I had this come up in my react-native project, after adding a new preset to my
.babelrc. Solved by switching them around:I have the save problem. It works fine like this.