无法安装React应用程序依赖项,因为node_modules文件夹不见了,并且会引发错误
P粉616111038
P粉616111038 2023-09-04 17:12:27
[React讨论组]
<p>我正在尝试安装一个React应用,但是无法安装,它总是给出以下错误并且整个node_modules文件夹消失了。</p> <pre class="brush:php;toolbar:false;">npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! Found: react-scripts@5.0.1 npm ERR! node_modules/react-scripts npm ERR! react-scripts@&quot;5.0.1&quot; from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer react-scripts@&quot;^4.0.0&quot; from @craco/craco@6.4.5 npm ERR! node_modules/@craco/craco npm ERR! @craco/craco@&quot;^6.4.3&quot; from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See /Users/xoxo/.npm/eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR! /Users/xoxo/.npm/_logs/2023-01-24T15_48_03_164Z-debug-0.log</pre> <p>而且它也不让我安装<code>react-app-rewired</code></p> <p>我尝试了使用--force和--legacy-peer-deps,但是没有运气,我已经卡在这里3个小时了,无法从任何地方解决它。还尝试了清除缓存并重新安装的方法,但是也没有运气。</p> <p>对于一些私有包,我使用了<code>npm auth</code>和<code>$NPM_TOKEN</code>,但仍然出现以下错误:</p> <pre class="brush:php;toolbar:false;">npm auth npm ERR! code EUSAGE npm ERR! npm ERR! Manage package owners npm ERR! npm ERR! Usage: npm ERR! npm owner add &lt;user&gt; &lt;package-spec&gt; npm ERR! npm owner rm &lt;user&gt; &lt;package-spec&gt; npm ERR! npm owner ls &lt;package-spec&gt; npm ERR! npm ERR! Options: npm ERR! [--registry &lt;registry&gt;] [--otp &lt;otp&gt;] npm ERR! [-w|--workspace &lt;workspace-name&gt; [-w|--workspace &lt;workspace-name&gt; ...]] npm ERR! [-ws|--workspaces] npm ERR! npm ERR! alias: author npm ERR! npm ERR! Run &quot;npm help owner&quot; for more info npm ERR! A complete log of this run can be found in: npm ERR! /Users/xoxo/.npm/_logs/2023-01-26T07_54_36_914Z-debug-0.log</pre></p>
P粉616111038
P粉616111038

全部回复(1)
P粉536532781

用以下方法解决了上述问题:

  1. 删除并重新克隆项目
  2. 创建了npmjs令牌,用于自定义私有包,并在.envrc文件中更新了它。
  3. 所以在npm i失败后,使用了npm i --legacy-peer-deps,之前先运行了npm cache clean --force

哇!所有的依赖都被安装了

我最初犯的错误是尝试使用npm auth,但实际上并不需要,因为npm会从.envrc.npmrc文件中获取它

因此,如果你遇到类似的困难,请尝试使用这些步骤

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号