找不到所需的文件。名称:index.html

新手上路,请多包涵

我一直在研究这个 React 项目,几个月以来没有遇到这个错误。我没有对项目树中 index.html 文件的位置进行任何更改,这就是为什么我无法解释这个错误的原因。

我尝试了以下措施但没有成功:

  1. 更改公用文件夹的位置
  2. 更改公用文件夹内容的位置
  3. 更改 package-lock.json 的位置
  4. 更改 package.json 的位置
  5. npm 安装
  6. npm install react-scripts –save

请找到终端显示的错误:

 Could not find a required file.
Name: index.html
Searched in: /Users/Sujay/Documents/Documents/Learn Web Development the Hard Way/lacapsule/project/Dark Sky Map Bitbucket/darkskymap_frontend/public
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the frontend@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Sujay/.npm/_logs/2019-08-06T07_12_22_366Z-debug.log

Expected result : React project should launch without any issue.
Actual result: Error message in terminal mentioned above.

原文由 Sujay 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.5k
2 个回答

index.html 已从 /public 目录中移动/删除

您的项目在公共目录中有 index.html 文件吗?

如果没有,您可以在 此处获得 Create React App 使用 的那个

它应该在 <your project root>/public/index.html


如果您使用 Git 进行版本控制,它将能够告诉您是否移动或删除了某些内容。

运行 git status 查看更改的文件

原文由 Jonathan Irwin 发布,翻译遵循 CC BY-SA 4.0 许可协议

您的公用文件夹可能丢失了,只需使用 create-react-app 创建另一个应用程序并将 公用文件夹 复制粘贴到此目录中

原文由 Ajay Tom George 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题