【问题标题】:Trying to install MobX but getting decorators error when start up the server尝试安装 MobX 但启动服务器时出现装饰器错误
【发布时间】:2018-10-31 21:27:15
【问题描述】:

当我安装 Mobx 和 Mobx 反应时,我收到以下错误。

./src/index.js
Error: The 'decorators' plugin requires a 'decoratorsBeforeExport' option, 
whose value must be a boolean. 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 'decorators'.

现在我已经弹出了依赖项并将 decorators-legacy 作为插件安装。这就是我的 package.json 文件中的内容

"babel": {
"plugins": [
  "transform-decorators-legacy"
 ],
 "presets": [
  "react-app"
  ]
},
"devDependencies": {
"@babel/plugin-proposal-decorators": "^7.1.2",
"babel-plugin-transform-decorators-legacy": "^1.3.5"
}

任何帮助都将不胜感激,因为过去几天这一直让我发疯。

【问题讨论】:

  • 你试过让你的配置看起来像the config in this issue吗?
  • babelrc 文件在哪里?
  • 在问题的最顶端。
  • 现在我收到以下错误./src/index.js SyntaxError: /Users/briankaty1/Desktop/mobx/mobx2/bird-cage/src/index.js: Unexpected token (7:16) 5 | import * as serviceWorker from './serviceWorker'; 6 | > 7 | ReactDOM.render(<App />, document.getElementById('root'));

标签: reactjs mobx mobx-react


【解决方案1】:

正如 Tholle 所写,该链接非常有帮助。我的 package.json 中的配置。

"babel": {
"presets": ["@babel/preset-env","react-app"],

"plugins": [
    ["@babel/plugin-proposal-decorators", { "legacy": true }],
    ["@babel/plugin-proposal-class-properties", { "loose": true }]
  ]
},
"devDependencies": {
"@babel/plugin-proposal-decorators": "^7.1.2",
"babel-plugin-transform-decorators-legacy": "^1.3.5"
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-20
    • 2018-12-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 2012-06-05
    • 2015-12-26
    相关资源
    最近更新 更多