Ant Design Mobile 报Cannot find module 'react-scripts/package.json' 错误

解决react-app-rewired与react-scripts兼容性问题
本文详细记录了使用create-react-app搭建AntdMobile脚手架后,遇到react-app-rewired与react-scripts兼容性问题的解决过程。通过添加react-scripts为dev依赖,成功解决了运行start命令时的模块找不到错误。

使用create-react-appa搭建Antd Modile脚手架之后,按照官网提示修改配置,运行命令如下:

yarn add react-app-rewired --dev

运行start命令时时抛出如下错误:

react-app-rewired start

module.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.<anonymous> (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

运行成功

 

转载于:https://www.cnblogs.com/jszhp/p/10462299.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值