Your project has a package.json but no node_modules folder
node_modules does not exist after cloning the projectShort answer
node_modules only exists after npm installs the dependencies. If the folder is missing, install has not run in this folder or it failed. If only dev tools are missing, NODE_ENV=production told npm to skip devDependencies. Run npm install in the folder that holds package.json, or npm ci when a lockfile exists.
Fix it fast
1Find out which cause you have
Check that you are in the folder that has package.json, whether node_modules exists there, and whether NODE_ENV is set. The output points at the cause below.
pwd && ls -a echo "NODE_ENV=$NODE_ENV" npm config get omit2Match what you see, then jump to its fix
- 1
No node_modules in ls -a, for example right after a git clone or a downloadThe install was never run in this folderFix - 2
node_modules exists, but tools such as react-scripts, vite or typescript are not foundNODE_ENV=production makes npm skip devDependenciesFix - 3
npm ci exits with an error saying package.json and the lockfile do not match, and installs nothingnpm ci refuses because the lockfile and package.json differFix
- 1
What does the error look like?
node_modules does not exist after cloning the projectDev tools such as react-scripts or tsc are missing although node_modules exists
Cause 1 of 3
The install was never run in this folder
1Check
node_modules is not stored in git, so a fresh copy of a project never has it. Confirm you are in the same folder as package.json.
ls package.json package-lock.json node_modules2Fix
Run the install. With no arguments, npm installs the dependencies listed in package.json into node_modules.
npm install3Verify
The folder appears and the project command runs.
ls node_modules | head
npm run buildConfirmed by docs.npmjs.com
Cause 2 of 3
NODE_ENV=production makes npm skip devDependencies
1Check
npm's omit setting defaults to 'dev' when NODE_ENV is production, so build tools listed under devDependencies are resolved but not placed on disk.
echo "$NODE_ENV"
npm config get omit2Fix
Install with the dev dependencies included, or unset NODE_ENV for the install step and set it again for the build or run.
npm install --include=dev
# or, for this shell only:
unset NODE_ENV && npm install3Verify
The tool now resolves from the project.
npx --no-install tsc --versionConfirmed by docs.npmjs.com
Cause 3 of 3
npm ci refuses because the lockfile and package.json differ
1Check
npm ci never rewrites the lockfile. If package.json was edited by hand, or the lockfile is missing, it exits with an error and nothing is installed.
ls package-lock.json && git status --short package.json package-lock.json2Fix
Run npm install once to bring the lockfile up to date, commit both files, then use npm ci in automation.
npm install
git add package.json package-lock.json3Verify
A clean install from the lockfile now works.
npm ciConfirmed by docs.npmjs.com
How do I stop it coming back?
- Keep node_modules out of git and put the install command in the README for the next person.
- In CI and Docker use npm ci with a committed package-lock.json.
- Do not set NODE_ENV=production globally on a machine you also build on; set it only for the run or the final image stage.
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
Web apps
npm start fails because react-scripts is not found
react-scripts: command not found
npm runs scripts with node_modules/.bin on the PATH.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fixWeb apps
Axios returns 401 from a React app but the login works elsewhere
Error: Request failed with status code 401
A 401 means the server received the request without valid credentials.
3 causes, each with a fix