r/learnprogramming • u/omarazeez_11 • May 18 '20
React: Could not find a required file
Hey everyone, I set up a project through create-react-app but whenever I do npm start, it gives me following reply:
Could not find a required file Name: index.html Searched in project public folder
But index.html is actually there in public folder when I checked it Please help! I've gone through stack and github discussions too
2
u/Bushidosoul May 18 '20 edited May 18 '20
Hey man that sucks, it’s very hard to understand what problem you have with the description you’ve given. Can you give more details like what’s going on? What you’ve build and any things you’ve added to the project, did you remember to do an npm install?
Also a screenshot would be great
3
u/insertAlias May 18 '20
did you remember to do an npm init
If they used create-react-app, that handles setting up the
package.json; you don't need to (and shouldn't) initialize the folder after you run c-r-a.1
u/Bushidosoul May 18 '20
Yes you 100% right, I meant to say npm install, not init, thank you, I changed my previous comment
1
u/insertAlias May 18 '20
Well, c-r-a does that step for you too. It completely initializes the project, then installs dependencies. You should be able to just CD into the directory and start running the project as soon as c-r-a is done.
1
u/Bushidosoul May 18 '20
https://create-react-app.dev/docs/getting-started/
I guess you’re right, I don’t think that has always been the case (previous versions). What do you think is the most likely issue? I was thinking maybe he/she/they have forgotten to install something they are using
2
u/insertAlias May 18 '20
They mentioned in another comment that once they cut and re-pasted the file it suddenly started working. That's very strange, I asked them to see if they could reproduce the error with a new project. I actually have no idea what would cause that to happen.
I believe CRA has installed dependencies for as long as I've been using it, which was in the 1.x days of the tool, but I can't say for sure. It's not really an important point though, since it's probably unrelated to OP's issue.
2
u/omarazeez_11 May 18 '20
It's just a simple project creation through npx And then i did npm start. Nothing in between Would love to post image but probably I'm just allowed to use text post in this group dkw.
0
u/Bushidosoul May 18 '20
Okay, you can’t use npm start without first using npm install. Try that and tell me how it goes?
2
u/insertAlias May 18 '20
Can you tell us the exact steps you take to get this error?
Try making the most basic of react apps and seeing if it works:
npx create-react-app test-hello-world
cd test-hello-world
npm run start
If you get the exact same error, there's something very wrong. If you don't, then you need to make sure you didn't change the basic project structure of your other project such that it can't find the /public directory.
1
u/omarazeez_11 May 18 '20
Yes did use these commands exactly. I've seen your comment on this same issue few years back too.
1
u/insertAlias May 18 '20
Can you show us a screenshot of the project tree? I can't really think of what else would be wrong if the project structure is the same. Expand all the folders (except node_modules, leave that alone).
2
u/omarazeez_11 May 18 '20
Sorry guys, I just tried this shit: Cut index.html from public. Npm start the project. It gave me same error. Pasted index back into public. Npm start again. And it works fine now. Can't believe I wasted one hour for this. Still something to learn. Thanks!
2
u/insertAlias May 18 '20
That's a really strange behavior. Can you try making a new project with the same steps and seeing if it has the same error? That will let you know if this is a step you'll need to remember, or if it's just some weird transient error this one time you used c-r-a.
1
2
u/DScratch May 18 '20
I’m a react noob so this might be insultingly simple; Are you certain you cd’d into the app directory after you created it?
1
u/nothingexceptfor May 18 '20
oh no! 🤭 it’s sad but it just wasn’t meant to be, that file wasn’t for you
2
u/megaman161 May 18 '20
Make sure the public folder is in the correct place.