启动react项目时,出现下面错误:
Error: The “injectBabelPlugin” helper has been deprecated as of v2.0. You can us
e customize-cra plugins in replacement - https://github.com/arackaf/customize-cr
a#available-plugins
at deprecate (E:\Vue\gzhipin-client\node_modules\[4mreact-app-rewired[24m
index.js:4:9)
at injectBabelPlugin (E:\Vue\gzhipin-client\node_modules\[4mreact-app-rewired[24m\index.js:18:12)
at Object.override [as webpack] (E:\Vue\gzhipin-client\config-overrides.js:3:14)
at Object. (E:\Vue\gzhipin-client\node_modules\[4mreact-app-rewired[24m\scripts\start.js:29:15)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gzhipin-client@0.1.0 start: react-app-rewired start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gzhipin-client@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache_logs\2020-09-11T0
7_14_12_081Z-debug.log
解决方法:
看到网上的说的可能是react-scripts包不全,需要npm install
或者npm install react-script
重新安装,本人尝试了一下不好使
其实,仔细看上面的错误,可以发现:
Error: The "injectBabelPlugin" helper has been deprecated as of v2.0. You can us
e customize-cra plugins in replacement - https://github.com/arackaf/customize-cr
a#available-plugins
意思是:
自2.0版起,“injectbabelplugin”助手已被弃用
react-app-rewired的新版本删除了injectBabelPlugin,这些方法被移动到一个名为’customize-cra’的新包中
所以需要重新将react-script降低到2.0版本
首先卸载react-script
npm uninstall react-app-rewired
然后,重新安装react-script2.0版本:
npm i react-app-rewired@2.0.2-next.0
参考:https://blog.csdn.net/qq_43693520/article/details/93332415