mobx-react icon indicating copy to clipboard operation
mobx-react copied to clipboard

cannot get decorators to work

Open phillipwinder opened this issue 9 years ago • 2 comments

Hi,

everytime I try to use decorators I get an "unexpected token" error at the @-sign.

setup:

package.json:

{
  "name": "web",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "mobx": "^3.2.2",
    "mobx-react": "^4.2.2",
    "react": "^15.6.1",
    "react-bootstrap": "^0.31.1",
    "react-dom": "^15.6.1",
    "react-router": "^4.1.2",
    "react-router-dom": "^4.1.2",
    "react-scripts": "1.0.10",
    "styled-components": "^2.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-1": "^6.24.1",
    "eslint-config-airbnb": "^15.1.0",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-jsx-a11y": "^5.1.1",
    "eslint-plugin-react": "^7.1.0"
  }
}

.babelrc:

{ 
  "presets": ["es2015", "react", "stage-1"],
  "plugins": ["transform-decorators-legacy"]
}

What am I missing?

phillipwinder avatar Aug 04 '17 09:08 phillipwinder

nevermind - used this and got it to work

phillipwinder avatar Aug 04 '17 14:08 phillipwinder

Glad you got it sorted :)

I'm pretty sure Create React App (which I suppose you're using because of react-scripts here) does not expose .babelrc config unless you eject. So that .babelrc you created there is not actually used, I believe. To get around that, you can use custom react scripts like you found, or eject and modify config then.

For what it's worth and for anyone reading this later on, we've got a number of helpful resources in the awesome list including instructions for using decorators with MobX in CRA, and, of course, in the docs for adding decorators when you can configure babel or working with MobX without decorators.

Closing this since I believe it's solved now, but feel free to follow up with any questions / further comments 👍

hawkins avatar Aug 04 '17 17:08 hawkins