使用create-react-appa搭建Antd Modile脚手架之后,按照官网提示修改配置,运行命令如下:
yarn add react-app-rewired --dev
运行start命令时时抛出如下错误:
react-app-rewired startmodule.js:550 throw err; ^Error: Cannot find module 'react-scripts/package.json' at Function.Module._resolveFilename (module.js:548:15) at Function.resolve (internal/module.js:18:19) at Object.(D:\project\pb-antd\node_modules\react-app-rewired\scripts\utils\paths.js:25:11) at Module._compile (module.js:653:30) at Object.Module._extensions..js (module.js:664:10) at Module.load (module.js:566:32) at tryModuleLoad (module.js:506:12) at Function.Module._load (module.js:498:3) at Module.require (module.js:597:17) at require (internal/module.js:11:18)
经过分析(过程略),替换为npm安装,出现以下提示:
npm WARN react-app-rewired@1.6.2 requires a peer of react-scripts@^1.0.14 but none is installed. You must install peer dependencies yourself.
解决方法
将 react-scripts添加到dev依赖中
yarn add react-scripts --dev
运行成功