Search code examples
dockerdockerfilefrontendcreate-react-appcicd

npm ERR! `npm ci` can only install packages when your package.json and package-lock.json


I need to install dependencies to build the frontend on CI/CD.

Dokerfile:

FROM node:18.12.1
enter code here
ENV CI="true"
WORKDIR /workdir
COPY package.json package-lock.json /workdir/
RUN npm ci

package.json

{
  "name": "v2",
  ...
  "dependencies": {
    "formik": "^2.2.9",
    "i18next": "^21.9.1",
    "lodash": "^4.17.21",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.3.0",
    "react-scripts": "5.0.1"
  },
  "devDependencies": {
    "typescript": "^4.9.5"
  },
  ...
}

In container I faced with this errors:

npm ERR! code EUSAGE
npm ERR! 
npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm ERR! 
npm ERR! Invalid: lock file's ajv@6.12.6 does not satisfy ajv@8.12.0
npm ERR! Missing: ajv@6.12.6 from lock file
...

Start on local environment works fine. How to fix this behavior?

I've tried remove node_modules and npm install


Solution

  • I ran into this problem because in my user settings (in ~/.npmrc) the legacy-peer-deps flag was set to true, while it wasn't so in the build environment.