React项目报错 : Missing class properties transform

本文介绍了一种在使用create-react-app过程中遇到的配置错误及其解决方法。通过调整.babelrc文件中的preset顺序,即env配置放置在stage-0之后,可以有效避免错误的发生。

如果你报了这个错误,并且你使用的是create-react-app的脚手架,你一定是运行了yarn run eject这个命令。
其实这个配置环境与我而言一直是一个比较玄幻的事情,一步只差就能让你的错误持续很久也解决不出来,目前的版本,推荐大家按照这个配置来搭建自己的项目,如果自己时间比较充足,也可以自己一步一步的试水。
下面来说一下我的解决方式,几乎不怎么费力我就把问题锁定到了.babelrc这个文件,然后我采取了单一变量法,我把好用的.babelrc文件拷贝过来,果然就不会报这个错误了,然后我把配置一个一个删掉,运行。最后我发现居然是在presets中的两个配置导致的,我把env这个配置写到了state-0的后面,然后我把他们两个的顺序倒过来,果然就不会报这个错了。
在这里多说两句,官方文档已经明确表示过了,env已经囊括了es2015,es2016等配置,所以写了这一个,其他的就不再需要了。

{ "presets": [
    "react",
    "env",
    "stage-0"   //这个要写在env的后面
    ], "plugins": ["transform-decorators-legacy"]}
error: index.js: Cannot find module '@babel/plugin-transform-class-properties' Require stack: - D:\AwesomeProject\node_modules\@babel\core\lib\config\files\plugins.js - D:\AwesomeProject\node_modules\@babel\core\lib\config\files\index.js - D:\AwesomeProject\node_modules\@babel\core\lib\index.js - D:\AwesomeProject\node_modules\metro-transform-worker\src\index.js - D:\AwesomeProject\node_modules\metro\src\DeltaBundler\Worker.js - D:\AwesomeProject\node_modules\jest-worker\build\workers\processChild.js Make sure that all the Babel plugins and presets you are using are defined as dependencies or devDependencies in your package.json file. It's possible that the missing plugin is loaded by a preset you are using that forgot to add the plugin to its dependencies: you can workaround this problem by explicitly adding the missing package to your top-level package.json. BUNDLE ./index.js error: index.js: Cannot find module '@babel/plugin-transform-class-properties' Require stack: - D:\AwesomeProject\node_modules\@babel\core\lib\config\files\plugins.js - D:\AwesomeProject\node_modules\@babel\core\lib\config\files\index.js - D:\AwesomeProject\node_modules\@babel\core\lib\index.js - D:\AwesomeProject\node_modules\metro-transform-worker\src\index.js - D:\AwesomeProject\node_modules\metro\src\DeltaBundler\Worker.js - D:\AwesomeProject\node_modules\jest-worker\build\workers\processChild.js Make sure that all the Babel plugins and presets you are using are defined as dependencies or devDependencies in your package.json file. It's possible that the missing plugin is loaded by a preset you are using that forgot to add the plugin to its dependencies: you can workaround this problem by explicitly adding the missing package to your top-level package.json. 这是报错 module.exports = { presets: ['module:metro-react-native-babel-preset'], plugins: [ [ 'import', { 'libraryName': '@ant-design/react-native', }, ], [ '@babel/plugin-transform-private-methods', { loose: true } ], [ '@babel/plugin-transform-class-properties', { loose: true } ], [ '@babel/plugin-transform-private-property-in-object', { loose: true } ], ], }; 这是我刚改的
最新发布
08-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值