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

node.jsDockerNpmDockerfile

node.js Problem Overview


I've a dockerfile as below, but during RUN npm ci step, there is a warning,

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

which I can not able to figure out..

I tried with npm install rather npm ci and added the --package-lock flag, but I am still getting this warning. It’s a kind of warning that I have to ignore it or what should I do to solve this?

Step 12/26 : RUN npm ci --production --package-lock &&     npm ci --production --package-lock --prefix ./ui-runner
 ---> Running in 3473c209b98c
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...
npm WARN old lockfile

Here is my Dockerfile.

FROM node:14.17.1-alpine3.13 AS builder
WORKDIR /usr/src/app
COPY package.json package-lock.json* ./
COPY ui-runner/package*.json ./ui-runner/
COPY .npmrc .npmrc
COPY ui-runner/.npmrc ./ui-runner/.npmrc
RUN npm -g install [email protected]
RUN npm ci --production --package-lock && \
    npm ci --production --package-lock --prefix ./ui-runner
RUN rm -f .npmrc && \
    rm -f ui-runner/.npmrc

FROM node:14.17.1-alpine3.13
WORKDIR /usr/src/app
RUN apk update && apk add --no-cache curl bash
RUN addgroup -g 1001 test && \
    adduser -S -u 1001 -G test test
RUN chown -R test /usr/src/app && \
    chmod 755 /usr/src/app
COPY --from=builder /usr/src/app /usr/src/app
COPY . .
RUN npm run build:docker
USER test
EXPOSE 3000 9183
CMD [ "npm", "run", "start:ui-runner" ]

node.js Solutions


Solution 1 - node.js

There are several ways to deal with this:

  1. Ignore it. It's just a warning and does not affect the installation of modules.

  2. Run npm install --package-lock-only (with the newer version of npm) to regenerate a package-lock.json. Commit the updated version of package-lock.json to the repo/Docker image or whatever.

  3. Downgrade npm to an older version in production. Consider running npm version 6 as that is what ships with the current (as of this writing) Long Term Support (LTS) version of Node.js. In the case being asked about in this question, I imagine you can just leave out the RUN npm -g install [email protected] from the Dockerfile and instead use the version of npm that is installed with the Docker image (which in this case will almost certainly be npm@6 since that is what ships with Node.js 14.x).

  4. If you already have a version of npm installed but want to run one command with an older version of npm but otherwise keep the newer version, you can use npx (which ships with npm) to do that. For example, npx npm@6 ci would run npm ci with npm version 6 even if you have version 7 installed.

Solution 2 - node.js

An easy solution to this is to use NVM to manage your node versions. Especially on Linux this saves a lot of trouble with file permissions, developing in different environments, etc. NPM recommends this in their documentation here.

This error for me was solved by switching Node.js versions with nvm,

nvm install 14
nvm use 14

It is always an easy thing to try and switch to a slightly older or newer Node.js version if you are running into weird Node.js or npm issues.

Solution 3 - node.js

I am having the same problem as well after upgrading my npm version. It seems like a bug from npm 7.19.1, and I'd suggest to downgrade to an older version.

You can check below for all the npm versions

https://www.npmjs.com/package/npm?activeTab=versions

Install the desired version with this command in the console, and substitute "V" with your desired version:

npm install -g npm@"V"

Solution 4 - node.js

I had a similar problem but upgrading npm npm i -g npm on my machine before building the image solved it for me. You may still get the warn message but the image build process won't be halted.

Solution 5 - node.js

TL;DR

As Trott suggested it is totally fine to ignore the warning. To fix the warning/problem keep reading.

The problem/warning is with the line:

RUN npm -g install npm@7.19.1

Removing this line should fix the problem/warning.

Explanation

The package-lock generated which is part of your source repository ideally is generated with npm version < npm@7 which ships with Node.js <= [email protected]. My guess comes from your first line of Dockerfile.

FROM node:14.17.1-alpine3.13 AS builder

For example Node.js LTS v14.17.1 ships with [email protected]. See the full release list here.

npm@5, npm@6 generate package-lock@v1, which is now a legacy release as per this link. And npm@7 which is the latest release generates package-lock@v2. When you do: npm -g install [email protected]. It overrides your existing package-lock@v1 with package-lock@v2 giving out the warning in the process.`

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

The updated Dockerfile should look like this:

FROM node:14.17.1-alpine3.13 AS builder
WORKDIR /usr/src/app
COPY package.json package-lock.json* ./
COPY ui-runner/package*.json ./ui-runner/
COPY .npmrc .npmrc
COPY ui-runner/.npmrc ./ui-runner/.npmrc
RUN npm ci --production --package-lock && \
    npm ci --production --package-lock --prefix ./ui-runner
RUN rm -f .npmrc && \
    rm -f ui-runner/.npmrc

FROM node:14.17.1-alpine3.13
WORKDIR /usr/src/app
RUN apk update && apk add --no-cache curl bash
RUN addgroup -g 1001 test && \
    adduser -S -u 1001 -G test test
RUN chown -R test /usr/src/app && \
    chmod 755 /usr/src/app
COPY --from=builder /usr/src/app /usr/src/app
COPY . .
RUN npm run build:docker
USER test
EXPOSE 3000 9183
CMD [ "npm", "run", "start:ui-runner" ]

Solution 6 - node.js

I was facing a similar issue. After reading the previous comments, I noticed that the Node.js version installed on my machine was v14.17.5 and the npm version was v7.19.1. Referring to version history lookup and downgrading npm to v6.14.14 (compatible against node v14.17.5) resolved issue.

Solution 7 - node.js

First check for your Node.js version: Go to a cmd prompt and

node -v

Based on the version, check the node-sass version and install it:

npm node-sass@version

From node-sass:

Node 16  -  6.0+
Node 15  -  5.0+
Node 14  -  4.14+
Node 13  -  4.13+,
Node 12  -  4.12+
Node 11  -  4.10+,
Node 10  -  4.9+,
Node 8   -  4.5.3+,
Node <8  -  <5.0

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsemuralView Question on Stackoverflow
Solution 1 - node.jsTrottView Answer on Stackoverflow
Solution 2 - node.jsGreggory WileyView Answer on Stackoverflow
Solution 3 - node.jsEliView Answer on Stackoverflow
Solution 4 - node.jsKuthumi PeppleView Answer on Stackoverflow
Solution 5 - node.jsaitchkhanView Answer on Stackoverflow
Solution 6 - node.jsAakash GoplaniView Answer on Stackoverflow
Solution 7 - node.jsPrarthan RameshView Answer on Stackoverflow