Last updated: Apr 4, 2024
Reading timeยท3 min
To resolve the warning "npm WARN old lockfile The package-lock.json file was created with an old version of npm":
npm install --package-lock-only
command to resolve any conflicts
and update your package-lock.json
file.node_modules
and package-lock.json
.npm install
.package-lock.json
file to your repository.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.
npm install --package-lock-only
If you get an error, try to run the command with the --legacy-peer-deps
flag
as well.
npm install --package-lock-only --legacy-peer-deps
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
.
npm
command scoped to a versionAnother 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.
npm --version
You can run an npm command scoped to a specific npm
version using npx
.
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.
If you still get the warning, try to delete your node_modules
and
package-lock.json
(not package.json
) and rerun npm install
.
# ๐๏ธ (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.
Another thing you can try is to upgrade your version of NPM.
npm install -g npm@latest # ๐๏ธ If you get a permissions error on macOS / Linux sudo npm install -g npm@latest
If you get a permissions error on Windows, open CMD as an administrator and rerun the command.
To open CMD as an administrator:
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
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.