VERCEL 部署错误:"Module not found: Error: Can't resolve 'react' in '/vercel/path0/src'"



我在Vercel上为我已经部署的React项目推送了一个新的更新后,收到了这个错误。在尝试了几种方法来解决它,但都被证明是徒劳的之后,我决定删除部署并完全重新部署它,但我仍然遇到了同样的问题。

[11:46:57.878] Cloning github.com/eimaam/myPortfolio (Branch: main, Commit: e7ba338
[[11:46:59.279] Cloning completed: 1.401s
[11:46:59.646] No Build Cache available
[11:46:59.702] Running "vercel build"
[11:47:00.346] Vercel CLI 28.4.7
[11:47:00.715] Installing dependencies...
[11:47:14.317] npm WARN deprecated source-map-resolve@0.6.0: See https://github.com/lydell/source-map-resolve#deprecated
[11:47:14.322] npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
[11:47:25.008] npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
[11:47:35.787] 
[11:47:35.787] added 1470 packages in 35s
[11:47:35.788] 
[11:47:35.788] 204 packages are looking for funding
[11:47:35.788]   run `npm fund` for details
[11:47:35.844] Detected `package-lock.json` generated by npm 7+...
[11:47:35.844] Running "npm run build"
[11:47:36.222] 
[11:47:36.222] > profile@0.1.0 build
[11:47:36.222] > react-scripts build
[11:47:36.222] 
[11:47:37.956] Creating an optimized production build...
[11:47:38.935] Failed to compile.
[11:47:38.935] 
[11:47:38.935] Module not found: Error: Can't resolve 'react' in '/vercel/path0/src'
[11:47:38.935] 
[11:47:38.936] 
[11:47:38.966] Error: Command "npm run build" exited with 1][1]

我尝试过这些命令,它对我很有效:

1-git rm-r-cached从git存储库的索引中删除所有文件和目录,但将它们保留在本地文件系统中。

2-git add--all将所有文件和目录,包括未跟踪的文件,添加到git存储库的索引中。

3位提交-a-m";版本控制未跟踪的文件">创建一个新的提交,其中包括索引中的所有更改,包括修改和删除。提交消息是";版本控制未跟踪的文件";。

4位推送源主机将本地提交推送到名为"的远程存储库;原点";而分支";"大师";。将本地更改与远程存储库同步。

最新更新