Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm start stops with Could not find a required file in a React app

ErrorCould 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.

  • Applies to react-scripts 5, Node.js 22, npm 10
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 src
  2. 2Match what you see, then jump to its fix

    1. 1Searched 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. 2Name: index.html and Searched in ends with /public.public/index.html was deleted, renamed or movedFix
    3. 3Name: index.js, or index.tsx, and Searched in ends with /src.There is no src/index fileFix

What does the error look like?

  • Could not find a required file.
  • Name: index.html
  • Searched 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.html

2Fix

Change into the folder that holds package.json and public, then start again.

cd my-app
npm start

3Verify

The dev server starts and the Searched in message is gone.

npm start

Confirmed by raw.githubusercontent.com

Did this fix it?

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 public

2Fix

Put the file back at public/index.html. Restore it from version control if you have it.

git checkout -- public/index.html

3Verify

The file exists at the exact path, and npm start runs.

ls public/index.html && npm start

Confirmed by raw.githubusercontent.com

Did this fix it?

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.js

3Verify

src/index.* exists and npm start runs.

ls src/index.* && npm start

Confirmed by raw.githubusercontent.com

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.