QA Interview Hub · Knowledge base · Quizzes · Українська

Cypress › Outdated-answer traps

How do you install Cypress correctly?

Cypress is installed locally as a dev dependency, npm install --save-dev cypress, so the lock file pins the version, not the machine. The installation has two parts: the package in node_modules and a Test Runner binary in a system cache, downloaded by a postinstall script for the package version. npm 12 blocks such scripts, so Cypress is approved or npx cypress install is run. CI caches the binary directory.

Cypress · Installation

Tests are green for a colleague, red for you, different on CI. Could you all have different Cypress versions?

Cypress is installed locally into the project as a dev dependency: npm install --save-dev cypress. Then package.json and the lock file pin the version, and you run it through npx cypress. A global install makes the version depend on the machine and breaks reproducibility.

How it works

The installation has two parts. The cypress package in node_modules is the CLI and API. The Test Runner application itself (the binary) is downloaded separately during npm install and stored in a system cache shared by projects: %LOCALAPPDATA%\Cypress\Cache on Windows, ~/.cache/Cypress on Linux, ~/Library/Caches/Cypress on macOS. The binary version follows the package version, so several versions can sit side by side in the cache.

Two parts of Cypress

in the project

npm package

Version in package.json and the lock file, the same for everyone.

in the system cache

Binary

Downloaded separately; cached across projects and CI runs.

Figure 1. The package pins the version, the binary lives in the cache.

Example: a typical installation

npm install --save-dev cypress   # package into devDependencies
npx cypress open                 # first run, creates the config
npx cypress verify               # is the binary in place and working
npx cypress install              # download the binary if missing
npx cypress version              # package and binary versions

On CI use npm ci (exactly per the lock file) instead of npm install and cache the binary folder, otherwise it is downloaded on every run. The folder can be changed with the CYPRESS_CACHE_FOLDER variable.

Limits and alternatives

A local install does not guarantee the same browser: Chrome and Firefox come from the system, and their versions differ. For full reproducibility on CI, use Cypress Docker images. The same rule applies to Playwright: npm i -D @playwright/test into the project and npx playwright install for browsers.

The binary cache and CI

The binary is downloaded by the package's postinstall script. If the package manager blocks such scripts (--ignore-scripts, a project policy, or npm 12+, which does it by default), there will be no binary and Cypress complains about it. Then run npx cypress install explicitly. The variable CYPRESS_INSTALL_BINARY=0 skips the download on purpose: handy for base Docker images where the binary is installed in a separate step. The cache folder is changed with CYPRESS_CACHE_FOLDER; that folder must exist every time Cypress launches.

# GitHub Actions: binary cache next to the npm cache (shortened)
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
  with: { node-version: 24, cache: npm }
- uses: actions/cache@v6
  with:
    path: ~/.cache/Cypress
    key: cypress-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- run: npm ci
- run: npx cypress verify

The cache key is built from the lock file: update the Cypress version, the key changes, and the new binary version is downloaded. The path ~/.cache/Cypress is valid for Linux runners; other OSes use a different one (see above).

Common mistakes

  • npm install -g cypress: every machine has its own version and "works on my machine" cannot be reproduced.
  • Not caching the binary on CI: hundreds of megabytes downloaded every time.
  • Updating the package without checking the binary: cypress verify shows the mismatch.

Check yourself

After npm ci on CI Cypress will not start and complains about a missing binary. Where do you look?

Answer

The package is installed but the binary was not downloaded or the cache is empty. npx cypress install fetches it and cypress verify confirms.

Why does a global install hurt a team project?

Answer

The version depends on the machine rather than the repository, so local and CI runs differ.

In the interview. Junior: Locally into the project as a dev dependency, so the version is pinned and the same for everyone and on CI. Middle/Senior: I know there is a package and a separate binary in the cache. On CI I use npm ci, cache the binary folder and pin a Docker image if needed, because browsers stay system-level.

More articles in this chapter