"Could not find a required file" 在 `yarn start`

"Could not find a required file" on `yarn start`

我设置了 create-react-app 并尝试在本地主机上 运行 App.js,但是在执行 yarn start 时我收到以下错误消息:

22:23 $ yarn start
yarn run v1.3.2
$ react-scripts start
Could not find a required file.
  Name: index.html
  Searched in: /Users/-----/Desktop/---/----/hw/HW-REPO/hw-name/public
error Command failed with exit code 1.

我已经用 yarn install 安装了 yarn,所以我不确定我的代码或文件结构是否有问题。

文件结构如下:

app-name
 -client
   --public
     ---index.html
     ---manifest.json
   --src
     ---Components
        ----various folders
     ---App.js
     ---App.test.js
     ---index.js
 -database
 -model
 -gitignore
 -package-lock.json
 -package.json
 -server.js
 -yarn.lock

更新:我将 yarn.lock and package.json 移到 client 文件夹中,再次 yarn install,然后 运行 yarn start. 现在我看到了很好的 ol ' 浏览器中的错误消息。我不是 100% 确定随机播放文件是否有效,或者它是否再次 yarn install 但至少它现在可以工作了。

@Tsardines 我遇到了同样的问题,但我的程序引用的 'Could not find a required file' 是 'index.js'。

$ yarn start
# yarn run v1.13.0
# warning ..\..\..\..\package.json: No license field
$ react-scripts start
# Could not find a required file.
# Name: index.js`

这是因为我的 index.js 文件位于项目的根文件夹中,而不是 在 'src' 文件夹中。

我将文件移动到 src 文件夹,运行 'yarn start'。 急!

在我的例子中,我在 vs code 中打开了错误的文件夹,并试图从他们的 运行 npm start 开始,但 npm 没有在该路径中找到 index.html,所以我查看了正确的路径并重新打开文件夹,没有问题。希望这对一些新手有所帮助。

在我的例子中,命令 npm audit fix --force 在 package.json 中更改 react-scripts 的版本当我使用 --template typescript 创建应用程序时,旧版本的 react-scripts 找不到 index.js ,但我有 index.tsx

我通过删除 package-lock.json、node-modules 文件夹并从 package.json 中删除 react-scripts 来解决这个问题,然后 npm i react-scripts