Node.js

Delete node_modules and reinstall cleanly

When packages act strangely, throw node_modules away and install exactly what the lock file lists.

  1. Delete node_modules
    Terminal
    rm -rf node_modules

    Run it in the folder that has package.json. Nothing of yours is lost: everything in it can be downloaded again.

  2. Install exactly what the lock file lists
    Terminal
    npm ci

    No package-lock.json in the project? Use npm install instead.

  3. Still odd? Clear npm's download cache and try again
    Terminal
    npm cache clean --force && npm ci

Check it worked

  1. Check the packages are back
    Terminal
    npm ls --depth=0

    Lines marked missing or invalid mean something is still wrong.

  1. Delete node_modules
    Terminal · Ubuntu / Debian
    rm -rf node_modules

    Run it in the folder that has package.json. Nothing of yours is lost: everything in it can be downloaded again.

  2. Install exactly what the lock file lists
    Terminal · Ubuntu / Debian
    npm ci

    No package-lock.json in the project? Use npm install instead.

  3. Still odd? Clear npm's download cache and try again
    Terminal · Ubuntu / Debian
    npm cache clean --force && npm ci

Check it worked

  1. Check the packages are back
    Terminal · Ubuntu / Debian
    npm ls --depth=0

    Lines marked missing or invalid mean something is still wrong.

  1. Delete node_modules
    PowerShell
    Remove-Item -Recurse -Force node_modules

    Run it in the folder that has package.json. Nothing of yours is lost: everything in it can be downloaded again.

  2. Install exactly what the lock file lists
    PowerShell
    npm ci

    No package-lock.json in the project? Use npm install instead.

  3. Still odd? Clear npm's download cache and try again
    PowerShell
    npm cache clean --force; npm ci

Check it worked

  1. Check the packages are back
    PowerShell
    npm ls --depth=0

    Lines marked missing or invalid mean something is still wrong.

New to dependency? I explain it in plain English on Layman Terms.