npm WARN old lockfile The package-lock.json file was created with an old version of npm

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
3 min

banner

# npm WARN old lockfile The package-lock.json file was created with an old version of npm

To resolve the warning "npm WARN old lockfile The package-lock.json file was created with an old version of npm":

  1. Run the npm install --package-lock-only command to resolve any conflicts and update your package-lock.json file.
  2. Delete your node_modules and package-lock.json.
  3. Install your modules with npm install.
  4. Commit the updated package-lock.json file to your repository.
shell
npm WARN old lockfile npm WARN old lockfile The package-lock.json file was created with an old version of npm, npm WARN old lockfile so supplemental metadata must be fetched from the registry. npm WARN old lockfile npm WARN old lockfile This is a one-time fix-up, please be patient...

The first thing you should try is to run the npm install command with the --package-lock-only flag.

shell
npm install --package-lock-only

npm install with package lock only flag

If you get an error, try to run the command with the --legacy-peer-deps flag as well.

shell
npm install --package-lock-only --legacy-peer-deps

npm install with legacy peer deps

If your package-lock.json file is updated successfully using your more recent version of NPM, commit it to your repository.

The warning is usually shown when your package-lock.json file is created using an older version of npm.

# Running your npm command scoped to a version

Another thing you could try is to run your command with npm scoped to a specific, older version.

You can use the npm --version command to get your npm version.

shell
npm --version

issue npm version command

You can run an npm command scoped to a specific npm version using npx.

shell
npx npm@6 install npx npm@6 install react npx npm@6 --version

The npx npm@6 prefix allows you to issue an npm command scoped to npm version 6 without having to downgrade your npm version for a single command.

# Delete your node_modules and reinstall your dependencies

If you still get the warning, try to delete your node_modules and package-lock.json (not package.json) and rerun npm install.

shell
# ๐Ÿ‘‡๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json # ๐Ÿ‘‡๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json # ๐Ÿ‘‡๏ธ clean npm cache npm cache clean --force # ๐Ÿ‘‡๏ธ install packages npm install # ๐Ÿ‘‡๏ธ if you get an error npm install --legacy-peer-deps # ๐Ÿ‘‡๏ธ if you use YARN yarn install

Now that your package-lock.json file is updated successfully, commit it to the repository.

If none of the suggestions helped, try to upgrade your version of NPM.

# Try to upgrade your version of NPM

Another thing you can try is to upgrade your version of NPM.

shell
npm install -g npm@latest # ๐Ÿ‘‡๏ธ If you get a permissions error on macOS / Linux sudo npm install -g npm@latest

upgrade npm version

If you get a permissions error on Windows, open CMD as an administrator and rerun the command.

To open CMD as an administrator:

  1. Click on the Search bar and type CMD.

  2. Right-click on the Command Prompt application and click "Run as administrator".

run cmd as administrator

  1. Rerun the command.
shell
npm install -g npm@latest npm install -g npm@latest --force

Try to rerun npm install after upgrading npm.

Once you manage to update your package-lock.json file, make sure to commit it to your repository.

If none of the suggestions helped and the warning is still shown when you run npm install, you could just ignore it as it doesn't affect the installation of NPM modules.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2025 Borislav Hadzhiev