skip to Main Content

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 [email protected] does not satisfy [email protected]
npm ERR! Missing: [email protected] from lock file
...

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

I’ve tried remove node_modules and npm install

2

Answers


  1. Chosen as BEST ANSWER

    I ran into this problem because in my user settings(~/.npmrc) the legacy-peer-dns flag was set to true.


  2. Try to add the following Dockerfile:

    FROM node:18.12.1
    
    ENV CI="true"
    
    WORKDIR /workdir
    
    # Remove package-lock.json
    RUN rm package-lock.json
    
    # Install npm dependencies
    RUN npm install
    
    # Copy package.json and package-lock.json to the container
    COPY package.json package-lock.json /workdir/
    
    # Copy the rest of the application code
    COPY . /workdir/
    
    # Build your application
    RUN npm run build
    
    # Specify the command to run your application
    CMD [ "npm", "start" ]
    

    Let me know if this works.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search