Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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" ]
like image 373
semural Avatar asked Jul 05 '21 18:07

semural


3 Answers

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.

like image 124
Trott Avatar answered Oct 19 '22 05:10

Trott


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.

like image 43
Kuthumi Pepple Avatar answered Oct 19 '22 06:10

Kuthumi Pepple


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.

like image 7
Greggory Wiley Avatar answered Oct 19 '22 05:10

Greggory Wiley