node_modules folder and package-lock.json, then run npm install again to rebuild them cleanly. This clears most corrupted-install problems.Guide
When npm misbehaves, a handful of fixes solve almost everything. Here they are, in order of what to try first.
If an install seems broken or a package acts strangely, the single most effective fix is to
delete the generated files and rebuild them from your package.json and lockfile.
Remember: node_modules is disposable — the two small files are the source of truth.
The classic clean reinstall
$ rm -rf node_modules package-lock.json # Mac/Linux
$ npm install node_modules folder and package-lock.json by handnpm install in the terminal to rebuild them from scratchRemove-Item -Recurse -Force node_modules, package-lock.jsonThis clears out corrupted or half-installed packages. It's safe: everything is rebuilt from package.json. It's the first thing to try for mysterious errors.
npm keeps a cache of downloaded packages to speed things up. Very occasionally that cache gets corrupted and causes odd download errors. Clearing it forces fresh downloads:
Clear the download cache
$ npm cache clean --force
$ npm install You rarely need this, but it's the next thing to try if a clean reinstall alone didn't fix a download/integrity error.
If you see a warning about an unsupported engine, a package needs a different Node version than
you have. Check what the project asks for (its engines field) against what you're
running:
Check and switch Node version
$ node -v # what you have
$ # this project's package.json wants: >=22.12.0
$ nvm install 22 # with the nvm version manager
$ nvm use 22 node -v with the project's engines requirementMismatched Node versions are a top cause of installs that work on one machine but not another. Matching engines fixes it.
Seeing EACCES or "permission denied", usually during a global install? The instinct
is to retype the command with sudo — resist it. sudo
tends to create files your normal user can't manage later, making the problem worse over time.
npm install inside the project rarely hits permission issues at all.This common error means Node went looking for a package and didn't find it. Two usual causes:
npm install (to get everything) or npm install x (to add that specific one). Also check the name is spelled exactly right.npm run dev was already running, stop it (Ctrl+C) and start it again so it sees the new package.Resolve a missing module
$ npm install # install everything package.json lists
$ # still missing one specific package?
$ npm install the-package-name Ctrl+C, then npm run dev againIf you just cloned a project and nothing works, the answer is almost always a plain 'npm install' you skipped.
One more, for teams: a Git merge conflict in package-lock.json looks scary but is routine — don't edit it by hand. Accept either side, then run npm install to let npm regenerate a correct lockfile, and commit that.
Up next: the cheat sheet — every command from this guide on one page, with its VS Code equivalent.
FAQ
node_modules folder and package-lock.json, then run npm install again to rebuild them cleanly. This clears most corrupted-install problems.package.json's engines field — a manager like nvm lets you switch Node versions per project.sudo — it usually makes permissions worse. Instead use a version manager (nvm) or fix your global folder's ownership. Local project installs rarely need elevated permissions at all.npm install, or npm install <pkg>) or your dev server is still running with the old state — stop it and start it again so it picks up the new package.