如何解决“已安装 cypress npm 软件包,但缺少 Cypress 二进制文件。”

问题描述 投票:0回答:5

我正在尝试在 GitLab CI 运行程序中下载并安装 Cypress 并获得此错误输出:

The cypress npm package is installed, but the Cypress binary is missing.
We expected the binary to be installed here: /root/.cache/Cypress/4.8.0/Cypress/Cypress
Reasons it may be missing:
- You're caching 'node_modules' but are not caching this path: /root/.cache/Cypress
- You ran 'npm install' at an earlier build step but did not persist: /root/.cache/Cypress
Properly caching the binary will fix this error and avoid downloading and unzipping Cypress.
Alternatively, you can run 'cypress install' to download the binary again.

我运行了建议的命令

cypress install
,但没有帮助。 接下来它说
You're caching 'node_modules' but are not caching this path: /root/.cache/Cypress
我不明白如何缓存模块并忽略它的路径。 接下来是
You ran 'npm install' at an earlier build step but did not persist
我在早期版本中确实有
npm install
,所以我将其替换为
npm ci
,因为在这种情况下赛普拉斯官方文档中建议这样做。

但没有解决方案。

以下是发生错误的相关行:

Dockerfile 内部:

COPY package.json /usr/src/app/package.json
COPY package-lock.json /usr/src/app/package-lock.json
RUN npm ci

在测试运行器内部:

docker-compose -f docker-compose-prod.yml up -d --build
./node_modules/.bin/cypress run --config baseUrl=http://localhost

package.json里面:

{
  "name": "flask-on-docker",
  "dependencies": {
    "cypress": "^4.8.0"
  }
}

有人能指出我正确的方向吗?

docker npm gitlab-ci cypress
5个回答
15
投票

您可能在两个不同的阶段运行

npm install
cypress run
。在这种情况下,cypress 缓存无法持久化,因此建议在运行
CYPRESS_CACHE_FOLDER
以及
install
时使用
cypress run/open
选项。命令看起来像这样,

CYPRESS_CACHE_FOLDER=./tmp/Cypress yarn install

CYPRESS_CACHE_FOLDER=./tmp/Cypress npx cy run [--params]

10
投票

这对我有帮助(Windows):

.\node_modules\.bin\cypress.cmd install --force

或者如果您使用的是 UNIX 系统:

./node_modules/.bin/cypress install --force

https://newbedev.com/the-cypress-npm-package-is-installed-but-the-cypress-binary-is-missing-591-code-example


0
投票

yarn cypress install --force
在运行测试对我有用之前


0
投票

我也遇到了同样的问题 我运行此代码以授予 jenkins 用户成为我的 cypress 项目文件夹的所有者 之后一切都OK了。

sudo chown -R jenkins: /你的 cypress 项目路径/


0
投票

在 gitlab CI 中,这终于对我有用了:

$CI_PROJECT_DIR
是一个全局可用的gitlab CI变量。

variables:
  # fix caching for .npm and cypress binary
  npm_config_cache: "$CI_PROJECT_DIR/.npm"
  CYPRESS_CACHE_FOLDER: "$CI_PROJECT_DIR/.cache/Cypress"

install:
  [...] # whatever you do in install
  cache:
    policy: pull-push
    paths:
      - "$CI_PROJECT_DIR/.npm"
      - "$CI_PROJECT_DIR/.cache/Cypress"
      - ./node_modules
    key:
      prefix: cache-$PROJECT_DIR
      files:
        - ./package-lock.json


© www.soinside.com 2019 - 2024. All rights reserved.