docker npm错误!`npm ci`只能在您的package.json和package-lock.json

jobtbby3  于 2023-06-05  发布在  Docker
关注(0)|答案(2)|浏览(325)

我需要安装依赖项以在CI/CD上构建前端。
文档文件:

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"
  },
  ...
}

在容器中,我遇到了这样的错误:

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
...

启动本地环境工作正常。如何修复此行为?
我已经尝试删除node_modulesnpm install

eyh26e7m

eyh26e7m1#

我遇到这个问题是因为在我的用户设置(~/.npmrc)中,legacy-peer-dns标志被设置为true

rm5edbpk

rm5edbpk2#

尝试添加以下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" ]

如果成功了告诉我。

相关问题