React-MobX Error: The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean

前端 未结 5 760
無奈伤痛
無奈伤痛 2021-02-12 11:52

I get the following error: If you are migrating from Babylon/Babel 6 or want to use the old decorators proposal, you should use the \'decorators-legacy\' plugin instead of \'dec

5条回答
  •  无人共我
    2021-02-12 12:42

    Answer are in the official document: https://mobx.js.org/best/decorators.html

    you can find many ways to enable it in section "Enabling decorator syntax"

    take the Babel 7 for example, create a project using mobx+create-react-app from scratch:

    npx create-react-app hello-mobx
    
    //This moves files around and makes your app’s configuration accessible.
    npm run eject
    
    npm install --save-dev babel-plugin-transform-decorators-legacy
    npm install --save-dev @babel/plugin-proposal-decorators
    npm install --save-dev @babel/plugin-proposal-class-properties
    
    

    edit package.json: package.json:

    "babel": {
      "plugins":[
        [
          "@babel/plugin-proposal-decorators",
          {
            "legacy":true
          }
        ],
        [
          "@babel/plugin-proposal-class-properties",
          {
            "loose":true
          }
        ]
      ],
      "presets":[
        "react-app"
      ]
    }
    

    install mobx:

    npm install mobx --save
    npm install mobx-react --save
    

    enjoy!

提交回复
热议问题