npm start stops with Could not find a required file in a React app
Could not find a required file.Short answer
react-scripts checks for two files before the dev server starts: public/index.html and a src/index file. If either is missing in the folder where you ran the command, it prints the file name and the folder it searched, then exits. Run npm start from the project root, restore the file, or rename it back.
Fix it fast
1Find out which cause you have
Read the two lines under the error. Name is the missing file and Searched in is the folder react-scripts looked in. Compare that folder with where you really are.
pwd ls public src2Match what you see, then jump to its fix
- 1
Searched in shows a path that is not your project, such as the parent folder or your home folder.npm start was run from the wrong folderFix - 2
Name: index.html and Searched in ends with /public.public/index.html was deleted, renamed or movedFix - 3
Name: index.js, or index.tsx, and Searched in ends with /src.There is no src/index fileFix
- 1
What does the error look like?
Could not find a required file.Name: index.htmlSearched in: /path/to/project/public
Cause 1 of 3
npm start was run from the wrong folder
1Check
react-scripts builds every path from the current working directory, so a folder without public/index.html fails even if the project is one level down.
pwd
ls package.json public/index.html2Fix
Change into the folder that holds package.json and public, then start again.
cd my-app
npm start3Verify
The dev server starts and the Searched in message is gone.
npm startConfirmed by raw.githubusercontent.com
Cause 2 of 3
public/index.html was deleted, renamed or moved
1Check
The path public/index.html is fixed in react-scripts. A file with another name or in another folder is not found.
ls -la public2Fix
Put the file back at public/index.html. Restore it from version control if you have it.
git checkout -- public/index.html3Verify
The file exists at the exact path, and npm start runs.
ls public/index.html && npm startConfirmed by raw.githubusercontent.com
Cause 3 of 3
There is no src/index file
1Check
react-scripts looks for src/index with one of these extensions: mjs, js, ts, tsx, json, jsx. It falls back to src/index.js when none exists. A file called main.js or app.js does not count.
ls src | grep -i '^index'2Fix
Rename your entry file to src/index.js (or index.tsx for TypeScript).
mv src/main.js src/index.js3Verify
src/index.* exists and npm start runs.
ls src/index.* && npm startConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Keep package.json, public and src together at the project root.
- Run project scripts from the root; a terminal tab opened in the parent folder is the usual slip.
- Do not rename public/index.html or the src/index entry file.
- Commit to version control, so a deleted file is one command to restore.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Back end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
Create React App says Node is too old, and npm will not run on the new one
npm does not support Node.js v10.19.0
The shell is running an old Node.js that is below the version Create React App needs.
3 causes, each with a fixBack end
npm audit stops with ENOLOCK because there is no lockfile
npm ERR! audit
npm audit sends the dependency tree from your lockfile to the registry.
2 causes, each with a fixBack end
npm says an override conflicts with a direct dependency
Override for react-error-overlay@^6.0.9 conflicts with direct dependency
npm refuses an override for a package you also depend on directly, unless both specs are exactly the same.
2 causes, each with a fixBack end
npm run build says react-scripts: Permission denied in CI
sh: react-scripts: Permission denied
The shell found node_modules/.bin/react-scripts but may not run it.
3 causes, each with a fixBack end
Babel cannot find @babel/plugin-proposal-private-property-in-object in a React app
Cannot find module '@babel/plugin-proposal-private-property-in-object'
babel-preset-react-app loads this Babel plugin but your project never lists it, so it only works while something else happens to install it.
2 causes, each with a fix