本站目前升级了全新主题zhime,该主题色彩更清新明亮。售价99元/套,你值得拥有,后台配置全,永久更新。

create-react-app报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’的解决方法

首先阐述一下遇到的情况,今天在使用create-react-app创建好项目,然后通过react-app-rewired自定义配置create-react-app后,发现报了下面的错误,当然,我通过react-app-rewired配置了mobx才报的。

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’

我记得我之前配置是没有问题的,于是打开了mobx的官方文档,看了一下,发现对于 babel 7, 有一个新的设置,参见 issue 1352 来查看设置示例。

接着我找到node_modules文件夹下的react-app-rewire-mobx文件夹,然后对index.js文件配置进行了更新,将原来的代码更新成了下面的代码,然后问题解决。

code
const {injectBabelPlugin} = require('react-app-rewired');

function rewireMobX(config, env) {
  return injectBabelPlugin(["@babel/plugin-proposal-decorators", { "legacy": true }], config);
}

module.exports = rewireMobX;

当然,你也可以直接在config-overrides.js下进行配置。

读完了点一下,作者能得积分

分享 微博 QQ

发表评论

发表评论