You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装react-toastify后React项目丢失react/index.js文件报错求助

解决React项目安装react-toastify后丢失react依赖的问题

Hey there, let's work through this issue together—this kind of dependency hiccup is super common, especially with older npm versions like the 5.0.0 you're using. Here's how to fix it step by step:

1. 彻底清理npm缓存与残留文件

Older npm versions are prone to caching corrupted dependency data. First, let's wipe that out:

npm cache clean --force

Then, delete both your node_modules folder and the package-lock.json file (this lock file might be holding onto broken dependency references from the failed install). You can do this via terminal:

rm -rf node_modules package-lock.json

2. 重新安装所有依赖

Now let's start fresh with a clean install:

npm install

After this finishes, double-check that the react folder exists in node_modules and that node_modules/react/index.js is present. If it's still missing, we'll install React explicitly next.

3. 手动安装React依赖

Sometimes when adding new packages, older npm can accidentally unpin or remove peer dependencies like React. Fix this by installing React directly:

npm install react --save

Run this command, then verify the index.js file is now in place.

4. (可选但推荐)升级npm版本

npm 5.0.0 has a lot of known bugs (that cb() never called! error is one of them). Since you're using Node.js 8.0.0, the most stable compatible npm version is 6.x. Upgrade it with:

npm install -g npm@6

This will prevent similar issues from popping up in future installs.

5. 验证项目能正常启动

Once all steps are done, try starting your project again:

npm start

为什么会出现这个问题?

That initial cb() never called! error is a well-documented bug in early npm 5 versions, which can cause incomplete or corrupted dependency installs. When you tried to add react-toastify, the bug likely interrupted the install process and left React's files missing—even re-running npm install didn't fix it because the corrupted lock file was still telling npm everything was okay.

内容的提问来源于stack exchange,提问作者Edper

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:44:13