英文:
npm ERR! `npm ci` can only install packages when your package.json and package-lock.json
问题
需要在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"
},
...
}
在容器中遇到以下错误:
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_modules
并运行npm install
。
英文:
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
答案1
得分: 2
因为在我的用户设置中(在 ~/.npmrc
中),legacy-peer-deps
标志被设置为 true
,而在构建环境中并非如此,所以我遇到了这个问题。
英文:
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.
答案2
得分: -1
尝试添加以下的 Dockerfile
:
FROM node:18.12.1
ENV CI="true"
WORKDIR /workdir
# 删除 package-lock.json
RUN rm package-lock.json
# 安装 npm 依赖
RUN npm install
# 将 package.json 和 package-lock.json 复制到容器中
COPY package.json package-lock.json /workdir/
# 复制剩余的应用程序代码
COPY . /workdir/
# 构建你的应用程序
RUN npm run build
# 指定运行应用程序的命令
CMD [ "npm", "start" ]
如果这个可以的话,请告诉我。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论