javascript `yarn start`上的“找不到所需的文件”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49724813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Could not find a required file" on `yarn start`
提问by Tsardines
I set up a create-react-appand I'm trying to run App.js on localhost, but upon doing yarn startI get the following error message:
我设置了一个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.
I'd already installed yarn with yarn install, so I'm not sure if there's something wrong with my code or with the file structure.
我已经用 安装了yarn yarn install,所以我不确定我的代码或文件结构是否有问题。
Here's the file structure:
这是文件结构:
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
采纳答案by Tsardines
Update: I moved yarn.lock and package.jsoninto the clientfolder, did yarn installagain, and then ran yarn start.Now I'm seeing good ol' error messages in the browser. I'm not 100% sure if shuffling the files around did the trick or if it was doing yarn installagain,but at least it's working now.
更新:我移动yarn.lock and package.json到client文件夹中,做了yarn install一遍,然后跑到yarn start.现在,我看到好醇”在浏览器中的错误消息。我不是 100% 确定混洗文件是否有效,或者它是否yarn install再次这样做,但至少它现在正在工作。
回答by V Jazz
In my case I opened my wrong folder in vs code and was trying to run npm start from their and npm did not find the index.html in that path, so I looked the correct path and reopened the folder and got no issue. Hope this will help some new beginner.
就我而言,我在 vs 代码中打开了错误的文件夹,并试图从它们运行 npm start 并且 npm 在该路径中没有找到 index.html,所以我查看了正确的路径并重新打开了该文件夹并没有出现问题。希望这会帮助一些新的初学者。
回答by user10968884
@Tsardines I was experiencing the same issue, but the 'Could not find a required file' my program was referencing was 'index.js'.
@Tsardines 我遇到了同样的问题,但我的程序引用的“找不到所需文件”是“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
$ 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
This was because my index.js file was in the root folder of my project, instead of being in the 'src' folder.
这是因为我的 index.js 文件在我的项目的根文件夹中,而不是在 'src' 文件夹中。
I moved the file to src folder, ran 'yarn start'. Presto!
我将文件移动到 src 文件夹,运行“纱线启动”。快!

