Published on Mar 31, 2025 5 min read

Fixing Slow or Stuck NPM Installs: Proven Ways to Speed Things Up

Running npm install is supposed to be straightforward. You hit the command, grab a coffee, and by the time you’re back—your project dependencies should be ready. But sometimes, npm seems to take forever. Worse, it gets stuck mid-installation, and no matter how long you wait, it doesn’t complete.

If you’re nodding along, you’re definitely not the only one. Many developers face this issue, especially when dealing with large projects or slow internet connections. The reasons for a sluggish or stuck npm install vary, from corrupted caches and registry delays to overcomplicated dependencies. Fortunately, you don’t need to be a DevOps wizard to solve it.

In this post, we’ll explore the common causes of a slow or frozen npm install and share practical, copy-paste-free steps to get your environment back on track.

1. Check Your Network Connection First

Before diving into configs and cache, check your internet connection. Since npm fetches packages from online registries, a weak or unstable connection can drag the process or cause it to freeze entirely.

Quick tip:
Try opening a couple of websites or streaming a short video. If things are buffering or timing out, your connection might be the real bottleneck. Restart your router or switch to a more stable network if possible.

2. Use a Mirror or Faster Registry

Sometimes, the default npm registry can respond slowly depending on your region. Switching to a mirror that’s geographically closer can make a big difference.

You can temporarily set a different registry with this command:

npm config set registry https://registry.npmmirror.com

This mirror is often faster, especially for users in Asia or regions with spotty connectivity to the default registry. You can always reset it to the official one later.

3. Clear Out the NPM Cache

The npm cache stores previously downloaded packages to avoid redownloading them, but it can become outdated or corrupted over time. A bloated or broken cache can lead to failed or stalled installs.

You can wipe the cache clean using:

npm cache clean --force

Once cleared, try reinstalling your packages. This forces npm to fetch fresh copies from the registry, reducing the chances of it getting stuck on corrupt files.

4. Add Logging to See What’s Happening

When npm install hangs without explanation, it can be helpful to add verbose logging so you can see where it’s getting stuck.

Use this command:

npm install --verbose

This will print more details during the installation, helping you spot where it’s slowing down—whether it’s fetching a particular package or stuck on a post-install script.

5. Bypass Dependency Conflicts

If your project has mismatched dependencies or peer dependency issues, especially in newer versions of npm, the install process might freeze during resolution.

You can bypass stricter checks by running:

npm install --legacy-peer-deps

This skips peer dependency enforcement and installs packages in a more lenient way, which often fixes freezing in older projects or complex setups.

6. Cut Down on Concurrent Downloads

If your machine or network struggles with too many simultaneous connections, npm might slow down or time out during installation.

To limit the number of concurrent connections npm uses, try:

npm config set maxsockets 3

This reduces how many packages npm tries to download at once, which can help prevent stalls on slower systems.

7. Remove and Rebuild node_modules

Sometimes, an existing node_modules folder or a corrupted package-lock.json file can block a clean installation. Deleting them and starting over often clears the path.

You can do this safely by running:

rm -rf node_modules package-lock.json

npm install

This ensures you’re installing everything fresh and avoids strange issues caused by outdated lockfiles or partial installations.

8. Update Your Node and NPM Versions

Old versions of Node.js or npm can sometimes cause compatibility issues. It’s good practice to keep both tools updated to the latest stable versions.

To update npm:

npm install -g npm

To switch Node.js versions, consider using a version manager like nvm. It makes testing with different versions easy and clean.

9. Use a Different Package Manager (Optional)

If you’ve tried everything and npm is still giving you grief, you could consider switching to an alternative package manager like Yarn or PNPM. Both are widely adopted and optimized for faster installs and improved dependency resolution.

For example, to use Yarn:

npm install -g yarn

yarn install

Many developers have found these tools to be faster and more reliable, especially for monorepos or larger applications.

10. Disable Scripts During Install (Temporary Fix)

Certain npm packages run extra scripts after installation, which can sometimes hang or take a long time to complete. If you suspect that a post-install script is the cause, you can skip running them:

npm install --ignore-scripts

Use this only if you’re troubleshooting and know what the scripts do—some packages need them to work properly.

11. Use Local Dependency Caching

In CI pipelines or when reinstalling often, you can speed up installs by caching node_modules or downloading dependencies in advance.

This doesn’t apply to all users, but if you’re working in a team or deploying frequently, it's worth looking into dependency caching strategies for your environment (like GitHub Actions, GitLab CI, or Docker volumes).

Final Thoughts

A stuck or slow npm install can feel like a massive roadblock when you're just trying to get started on a project. But most of the time, the fix is straightforward—whether it’s a matter of clearing the cache, switching registries, or tweaking a setting.

Remember: package management doesn't have to be painful. With the right tools and a few small adjustments, you can save time, reduce frustration, and keep your workflow running smoothly.

Next time npm hangs on install, come back to this checklist—and get back to coding faster.

Related Articles