[英]npm ci can only install packages with an existing package-lock.json or npm-shrinkwrap.json with lockfileVersion >= 1
This is the issue that I am facing when running the command npm ci
to install dependencies in my GitHub Action file.这是我在运行命令
npm ci
以在我的 GitHub Action 文件中安装依赖项时遇到的问题。
I am working on an expo managed app and using GitHub Actions
as a CI for triggering builds whenever I push my code to developmemt
branch.我正在开发一个 expo 管理的应用程序,并使用
GitHub Actions
作为 CI 来在我将代码推送到developmemt
分支时触发构建。
Here's my build script:这是我的构建脚本:
name: EAS PIPELINE
on:
push:
branches:
- development
workflow_dispatch:
jobs:
build:
name: Install and build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Setup Expo
uses: expo/expo-github-action@v6
with:
expo-version: 4.x
token: ${{ secrets.EXPO_TOKEN }}
expo-cache: true
- name: Install dependencies
run: npm ci
- name: Build on EAS
run: EAS_BUILD_AUTOCOMMIT=${{1}} npx eas-cli build --platform all --non-interactive
Here's the issue that I am facing Install dependencies
step.这是我在
Install dependencies
步骤中遇到的问题。
Run npm ci
npm ci
shell: /usr/bin/bash -e {0}
env:
EXPO_TOKEN: ***
npm ERR! cipm can only install packages with an existing package-lock.json or npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or later to generate it, then try again.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2021-10-28T15_16_06_934Z-debug.log
Error: Process completed with exit code 1.
After a lot of research, I was able to figure out that this happens when you are not using npm install
for installing dependencies.经过大量研究,我发现当您不使用
npm install
安装依赖项时会发生这种情况。 In my case, I was only using yarn for the dependencies so I was only having yarn.lock
file and no package-lock.json
file.在我的情况下,我只使用 yarn 作为依赖项,所以我只有
yarn.lock
文件而没有package-lock.json
文件。
One way to resolve this was using npm install
to install the dependencies, then you'll have a package-json.lock
file and CI
won't throw any error.解决此问题的一种方法是使用
npm install
安装依赖项,然后您将拥有一个package-json.lock
文件,并且CI
不会抛出任何错误。
And the other way if you only want to use yarn
, then you need to update that step in your eas-pipeline.yml
file for installing the dependencies.反之,如果您只想使用
yarn
,则需要在eas-pipeline.yml
文件中更新该步骤以安装依赖项。
*****************************************************************************************
- name: Install dependencies
run: |
if [ -e yarn.lock ]; then
yarn install --frozen-lockfile
elif [ -e package-lock.json ]; then
npm ci
else
npm i
fi
***************************************************************************************
As I wasn't able to find any solution on StackOverflow and it is our first go-to place to look for any issue.因为我无法在 StackOverflow 上找到任何解决方案,它是我们寻找任何问题的第一个去处。 So, I decided to write this answer here.
所以,我决定在这里写下这个答案。
Here's the original answer: https://github.com/facebook/docusaurus/issues/2846#issuecomment-691706184这是原始答案: https ://github.com/facebook/docusaurus/issues/2846#issuecomment-691706184
I had a similar error.我有一个类似的错误。
`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.
with bunch of missing dependency name following this error.在此错误之后缺少一堆依赖项名称。
I would run npm ci
locally and it would run successfully.我会在本地运行
npm ci
并且它会成功运行。 However, it would give me the error above when npm ci
is run in the CI pipeline and in my case it was because of the version difference of the Node.js installed in the environment that Jenkins pipeline is running in.但是,当
npm ci
在 CI 管道中运行时,它会给我上面的错误,在我的情况下,这是因为安装在 Jenkins 管道运行的环境中的 Node.js 的版本差异。
My local Node version was 16.x and in Jenkins container it was 12.x.我的本地节点版本是 16.x,在 Jenkins 容器中是 12.x。
Upgrading it fixed.升级它修复。
This same thing happened to me, and I couldn't figure it out for the longest time.同样的事情发生在我身上,我很长时间都想不通。 It turns out that I had
legacy-peer-deps=true
set globally, and I had no idea.事实证明,我在全局范围内设置了
legacy-peer-deps=true
,但我不知道。
This caused my npm install
command to alter the package-lock.json
in a way that broke the build on our CI server.这导致我的
npm install
命令以一种破坏我们 CI 服务器上的构建的方式改变了package-lock.json
。 I reset package-lock.json
with the version from master
, removed that npm
config, and reinstalled.我用
master
的版本重置了package-lock.json
,删除了那个npm
配置,然后重新安装。 Everything worked fine after that.之后一切正常。
Old post, but I found this while searching for this same error.旧帖子,但我在搜索同样的错误时发现了这个。 In my case I did have a
package-lock.json
file in my root directory.就我而言,我的根目录中确实有一个
package-lock.json
文件。 However, when opening it, I realized that there was a JSON syntax error that slipped in during a previous merge conflict.然而,当我打开它时,我意识到在之前的合并冲突中出现了一个 JSON 语法错误。 After running
npm i
again the file was fixed.再次运行
npm i
后,文件已修复。 The npm ERR! The 'npm ci' command can only install with an existing package-lock.json
npm ERR! The 'npm ci' command can only install with an existing package-lock.json
npm ERR! The 'npm ci' command can only install with an existing package-lock.json
wasn't a super helpful error in that case. npm ERR! The 'npm ci' command can only install with an existing package-lock.json
在这种情况下,这不是一个超级有用的错误。
For the people who has this issue on AWS Amplify.对于在 AWS Amplify 上遇到此问题的人。 You might have to run npm install and commit the package-lock.json file, then deploy again.
您可能必须运行 npm install 并提交 package-lock.json 文件,然后再次部署。
deleting deploy.json helped me, since the token is updated when overwritten删除 deploy.json 对我有帮助,因为令牌在被覆盖时会更新
rm ~/.config/configstore/@vkontakte/vk-miniapps-deploy.json
but I have other services但我有其他服务
If you're using pnpm
, you install node dependencies via this step:如果您使用的
pnpm
,则通过此步骤安装节点依赖项:
- name: Install Node.js dependencies
run: |
npm i -g pnpm
pnpm i
This happens sometimes because of the version difference of the Node.js installed in the environment that the pipeline is running in. To fixe this, I ran: $ firebase init hosting:github then type Y to set up workflow when asked to.有时会发生这种情况,因为管道运行环境中安装的 Node.js 的版本不同。为了解决这个问题,我运行了: $ firebase init hosting:github 然后在被要求时键入 Y 来设置工作流。 finally, add "npm i" as one of the scripts to run before deploying like this: npm i && npm ci && npm run build
最后,在部署之前添加“npm i”作为要运行的脚本之一:npm i && npm ci && npm run build
I was using npm
package manager and migrated to yarn
package manager removing package-lock.json
file.我正在使用
npm
包管理器并迁移到yarn
包管理器删除package-lock.json
文件。
I had this configuration in my .circleci/config.yml
file我的
.circleci/config.yml
文件中有这个配置
- node/install-packages
changed to变成
- node/install-packages:
pkg-manager: yarn
After battling with this issue for about 2 days, It's finally deploying successfully to Firebase Functions after deleting package-lock.json
from both the src
and src/functions
folders.在与此问题斗争了大约 2 天后,从
src
和src/functions
文件夹中删除package-lock.json
后,它终于成功部署到 Firebase Functions。
In my case the problem were some 'extraneous' packages, concretely local path dependencies.就我而言,问题是一些“无关”的包,具体是本地路径依赖项。 After removing them from package.json the problem was solved.
从 package.json 中删除它们后,问题就解决了。
I got the error message while running npm install
instead of npm ci
.我在运行
npm install
而不是npm ci
时收到错误消息。
On package.json I change this:在package.json上我改变了这个:
"overrides": {
"trim-newlines": "^3.0.1"
},
to: `到:`
"overrides": {
"trim-newlines": "^1.0.0"
}
` `
That Work for me successfully.成功地为我工作。
I had a similar problem deploying to heroku.我在部署到 heroku 时遇到了类似的问题。 I simply deleted the existing package-lock.json file and then ran
我只是删除了现有的 package-lock.json 文件然后运行
npm install
Merging the new lock file fixed the deploy.合并新的锁定文件修复了部署。
This occurred because the package lock file was not generated with npm
, despite the fact that the npm ci
requires npm
to install the packages.发生这种情况是因为包锁定文件不是使用
npm
生成的,尽管npm ci
需要npm
来安装包。 And because npm
requires package-lock.json
, we get this error.因为
npm
需要package-lock.json
,所以我们得到了这个错误。 To fix this error for GitHub actions, this what I did:为了修复 GitHub 操作的这个错误,我做了以下操作:
- run: yarn install --frozen-lockfile
- run: yarn lint
- run: yarn test:ci
Commit diff:提交差异:
In my case, I had this error with npm ci
while using Yarn.在我的例子中,我在使用 Yarn 时遇到了
npm ci
的错误。 I eventually figured out the version of Node I was using wasn't supported.我最终发现不支持我使用的 Node 版本。 I did the following:
我做了以下事情:
node -v
to confirm my node version (18.0.1) node -v
确认我的节点版本 (18.0.1)nvm use 16.13.0
node_modules
directorynode_modules
目录yarn.lock
yarn.lock
yarn
yarn
yard add
+ package namesyard add
+包名After this, the error no longer occurred and the app deployed correctly.此后,错误不再发生并且应用程序正确部署。
Yo I would literally pay someone to help me resolve the issue I'm having with this error.哟,我真的会付钱给某人来帮助我解决我遇到的这个错误的问题。 Lets hop on a zoom and i got u.
让我们跳上变焦,我得到了你。 get at me
让我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.