cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.02k stars 3.18k forks source link

Support Bun: Running Bun Install in Docker gives The Cypress App could not be downloaded #28722

Open ZachHandley opened 9 months ago

ZachHandley commented 9 months ago

Current behavior

Setting up a Dockerfile, when running install it fails to download Cypress and I don't quite understand why, seems like a Cypress issue

=> ERROR [install 4/8] RUN cd /temp/dev && bun install --frozen-lockfile                                                                             10.8s
------
 > [install 4/8] RUN cd /temp/dev && bun install --frozen-lockfile:
0.204 bun install v1.0.22 (b400b36c)
0.228 [21.66ms] migrated lockfile from package-lock.json
0.238  Saved lockfile
10.57 Installing Cypress (version: 12.8.1)
10.57 
10.57 [STARTED] Task without title.
10.57 [TITLE]  Downloading Cypress      0% 0s
10.57 [TITLE]  Downloading Cypress      1% 11s
10.57 [TITLE]  Downloading Cypress      1% 21s
10.57 [TITLE]  Downloading Cypress      2% 15s
10.57 [TITLE]  Downloading Cypress      4% 10s
10.57 [TITLE]  Downloading Cypress      5% 10s
10.57 [TITLE]  Downloading Cypress      6% 10s
10.57 [TITLE]  Downloading Cypress      7% 10s
10.57 [TITLE]  Downloading Cypress      8% 9s
10.57 [TITLE]  Downloading Cypress      10% 8s
10.57 [TITLE]  Downloading Cypress      11% 8s
10.57 [TITLE]  Downloading Cypress      13% 8s
10.57 [TITLE]  Downloading Cypress      14% 8s
10.57 [TITLE]  Downloading Cypress      16% 7s
10.57 [TITLE]  Downloading Cypress      18% 7s
10.57 [TITLE]  Downloading Cypress      20% 6s
10.57 [TITLE]  Downloading Cypress      22% 6s
10.57 [TITLE]  Downloading Cypress      24% 5s
10.57 [TITLE]  Downloading Cypress      26% 5s
10.57 [TITLE]  Downloading Cypress      28% 5s
10.57 [TITLE]  Downloading Cypress      30% 5s
10.57 [TITLE]  Downloading Cypress      32% 5s
10.57 [TITLE]  Downloading Cypress      34% 4s
10.57 [TITLE]  Downloading Cypress      36% 4s
10.57 [TITLE]  Downloading Cypress      37% 4s
10.57 [TITLE]  Downloading Cypress      39% 4s
10.57 [TITLE]  Downloading Cypress      41% 4s
10.57 [TITLE]  Downloading Cypress      43% 4s
10.57 [TITLE]  Downloading Cypress      46% 3s
10.57 [TITLE]  Downloading Cypress      47% 3s
10.57 [TITLE]  Downloading Cypress      49% 3s
10.57 [TITLE]  Downloading Cypress      50% 3s
10.57 [TITLE]  Downloading Cypress      52% 3s
10.57 [TITLE]  Downloading Cypress      54% 3s
10.57 [TITLE]  Downloading Cypress      57% 3s
10.57 [TITLE]  Downloading Cypress      59% 2s
10.57 [TITLE]  Downloading Cypress      60% 2s
10.57 [TITLE]  Downloading Cypress      62% 2s
10.57 [TITLE]  Downloading Cypress      65% 2s
10.57 [TITLE]  Downloading Cypress      67% 2s
10.57 [TITLE]  Downloading Cypress      68% 2s
10.57 [TITLE]  Downloading Cypress      70% 2s
10.57 [TITLE]  Downloading Cypress      71% 2s
10.57 [TITLE]  Downloading Cypress      73% 2s
10.57 [TITLE]  Downloading Cypress      74% 2s
10.57 [TITLE]  Downloading Cypress      75% 2s
10.57 [TITLE]  Downloading Cypress      76% 1s
10.57 [TITLE]  Downloading Cypress      77% 1s
10.57 [TITLE]  Downloading Cypress      79% 1s
10.57 [TITLE]  Downloading Cypress      81% 1s
10.57 [TITLE]  Downloading Cypress      83% 1s
10.57 [TITLE]  Downloading Cypress      85% 1s
10.57 [TITLE]  Downloading Cypress      86% 1s
10.57 [TITLE]  Downloading Cypress      89% 1s
10.57 [TITLE]  Downloading Cypress      91% 1s
10.57 [TITLE]  Downloading Cypress      92% 0s
10.57 [TITLE]  Downloading Cypress      94% 0s
10.57 [TITLE]  Downloading Cypress      96% 0s
10.57 [TITLE]  Downloading Cypress      97% 0s
10.57 [TITLE]  Downloading Cypress      98% 0s
10.57 The Cypress App could not be downloaded.
10.57 
10.57 Does your workplace require a proxy to be used to access the Internet? If so, you must configure the HTTP_PROXY environment variable before downloading Cypress. Read more: https://on.cypress.io/proxy-configuration
10.57 
10.57 Otherwise, please check network connectivity and try again:
10.57 
10.57 ----------
10.57 
10.57 URL: https://download.cypress.io/desktop/12.8.1?platform=linux&arch=x64
10.57 TypeError: undefined is not an object
10.57 
10.57 ----------

Desired behavior

bun install --frozen-lockfile should install

Test code to reproduce

I'm attempting to build a Dockerfile for Invoice Ninja, and this is the relevant code

FROM oven/bun:latest as base
WORKDIR /app
# Install dependencies into temp directory
# This will cache them and speed up future builds
FROM base as install
RUN mkdir -p /temp/dev
RUN bun upgrade
COPY package.json package-lock.json /temp/dev/
# Install with dev for build
RUN cd /temp/dev && bun install --frozen-lockfile

with the following for Cypress in the package.json

"cypress": "^12.5.1",

Cypress Version

12.8.1 was attempted install

Node version

Bun 1.0.22

Operating System

Docker

Debug Logs

No response

Other

No response

jonnalley commented 9 months ago

came here to say that I'm seeing the same thing with the same bun version (1.0.22) as well every version back to and including 1.0.17--but in my case I tried to install newer versions of cypress as well including 13.6.0 and 13.6.2 with no success.

bun version 1.0.16 doesn't exhibit these issues with the same two cypress 13.6.x versions mentioned above.

jonnalley commented 9 months ago

@ZachHandley I'm wondering if this is actually a bun issue perhaps. I had success in getting past this issue with using --ignore-scripts on my bun install command in my Dockerfile. See https://github.com/oven-sh/bun/issues/7689

MikeMcC399 commented 9 months ago

@ZachHandley

ZachHandley commented 9 months ago

@ZachHandley

Unfortunately not, NPM worked fine, it usually makes it to 99% before failing and it usually seems like it's right around when it would begin executing an install script, so not sure.

ZachHandley commented 9 months ago

But also I just want to say, I have 0 issues with any other packages using Bun so far, so support it or don't but this is almost definitely on Cypress or some weird interaction that shouldn't be happening

MikeMcC399 commented 9 months ago

@ZachHandley

I can reproduce your error using the Bun Docker image oven/bun. This is an image based on linux-x64 (Debian - 11.8).

Running the following in the Docker container:

# bun add cypress -D --ignore-scripts
bun add v1.0.25 (a8ff7be6)

 installed cypress@13.6.3 with binaries:
  - cypress

 1 package installed [2.85s]

then:

bun add cypress -D 
export DEBUG=cypress:*
bun cypress install

showed the following debug log:

# bun cypress install
  cypress:cli:cli cli starts with arguments ["/usr/local/bin/bun","/root/cy/node_modules/.bin/cypress","install"] +0ms
  cypress:cli NODE_OPTIONS is not set +0ms
  cypress:cli:cli program parsing arguments +5ms
  cypress:cli parsed cli options {} +154ms
  cypress:cli installing with options {} +0ms
  cypress:cli detecting arch { osPlatform: 'linux', osArch: 'x64' } +2ms
  cypress:cli arm uname -m result: { stdout: 'x86_64' }  +22ms
  cypress:cli version in package.json is 13.6.3, version to install is 13.6.3 +24ms
  cypress:cli Reading binary package.json from: /root/.cache/Cypress/13.6.3/Cypress/resources/app/package.json +0ms
  cypress:cli no binary installed under cli version +20ms
  cypress:cli checking local file /13.6.3 cwd /root/cy +1ms
  cypress:cli preparing to download and unzip version  13.6.3 to path /root/.cache/Cypress/13.6.3 +0ms
Installing Cypress (version: 13.6.3)

  cypress:cli needed Cypress version: 13.6.3 +0ms
  cypress:cli source url https://download.cypress.io/desktop/13.6.3?platform=linux&arch=x64 +1ms
  cypress:cli downloading cypress.zip to "/tmp/cypress-64.zip" +0ms
  cypress:cli Downloading package {
  url: 'https://download.cypress.io/desktop/13.6.3?platform=linux&arch=x64',
  proxy: null,
  downloadDestination: '/tmp/cypress-64.zip'
} +1ms
  cypress:cli expected file size 81 +413ms
  cypress:cli redirect version: 13.6.3 +0ms
  cypress:cli redirect url: https://cdn.cypress.io/desktop/13.6.3/linux-x64/cypress.zip +0ms
  cypress:cli Downloading package {
  url: 'https://cdn.cypress.io/desktop/13.6.3/linux-x64/cypress.zip',
  proxy: null,
  downloadDestination: '/tmp/cypress-64.zip'
} +0ms
  cypress:cli expected checksum 1631654914f16e0b5b797d9e4ceae044d55fcbcca543222c721a5230c4cd4d2aaf1a16d316454e019b6e1861be19cfe3050ca5468c754ac898ec42e29fb008c4 +128ms
⠹  Downloading Cypress      100% 0s
  cypress:cli downloading finished +22s
  cypress:cli verifying checksum and file size +1ms
  cypress:cli URL: https://download.cypress.io/desktop/13.6.3?platform=linux&arch=x64
✖ The Cypress App could not be downloaded.
  Does your workplace require a proxy to be used to access the Internet? If so, you must configure the HTTP_PROXY en…
  Otherwise, please check network connectivity and try again:
  ----------
  URL: https://download.cypress.io/desktop/13.6.3?platform=linux&arch=x64
  TypeError: undefined is not an object
  ----------
  Platform: linux-x64 (Debian - 11.8)
  Cypress Version: 13.6.3
The Cypress App could not be downloaded.

Does your workplace require a proxy to be used to access the Internet? If so, you must configure the HTTP_PROXY environment variable before downloading Cypress. Read more: https://on.cypress.io/proxy-configuration

Otherwise, please check network connectivity and try again:

----------

URL: https://download.cypress.io/desktop/13.6.3?platform=linux&arch=x64
TypeError: undefined is not an object

----------

Platform: linux-x64 (Debian - 11.8)
Cypress Version: 13.6.3
error: "cypress" exited with code 1

The error is:

TypeError: undefined is not an object

I can't say what the reason for this error is. I would guess that the Docker image oven/bun is missing some prerequisite that Cypress requires. Edit: see next comment.

Cypress provides compatible Docker images on the Docker Hub under cypress.

You may have more success if you use one of these Cypress Docker images as a base and install Bun on top. I have not tried this out myself. Edit: I can successfully run Cypress 13.6.3 natively under Ubuntu 22.04 using Bun 1.0.25. I haven't been able to do this yet in Docker.

Please note that I am a community contributor not a Cypress.io employee, so I don't make statements on behalf of Cypress.io. Any statement about whether Cypress supports Bun or not would need to come from the Cypress.io team.

The Cypress installation documentation lists npm, Yarn and pnpm as installation tools. There is no mention anywhere in the Cypress documentation about using Bun and so you can assume that Cypress is not regularly tested against Bun in Cypress' CI/CD process.

MikeMcC399 commented 9 months ago

@ZachHandley

The Docker image oven/bun does not include Node.js and this is required for a successful download of Cypress.

The documentation Installing Cypress > System requirements > Node.js implies this, although it is not specific to say that one of npm, Yarn or pnpm is required.

I can also reproduce this on Ubuntu with only Bun and no Node.js installed.

So the issue is that Cypress cannot be installed without Node.js. This would be a separate enhancement request to allow Cypress to be installed and run in a pure Bun environment with no Node.js present. It's also possible that this issue is a Bun bug, since Bun is advertised as a drop-in replacement for Node.js. Edit: The Bun / Node.js compatibility page shows multiple gaps in Bun's compatibility with Node.js.

Another enhancement request would be for Cypress Docker images to allow use with Bun.

MikeMcC399 commented 9 months ago

I used cypress/factory to build a Docker image and run Cypress using Bun.

Dockerfile contents:

ARG NODE_VERSION='20.11.0'

FROM cypress/factory
RUN npm install bun --global

COPY . /opt/app
WORKDIR /opt/app
RUN bun add cypress -D

It is not very elegant to have to use Node.js in parallel to Bun, and to install Bun with npm. This was just to show that it is possible. There is no claim that it is an optimal solution!

docker build . -t test
docker run -it test bun cypress run
jennifer-shehane commented 9 months ago

Adding a note to the docs about Node.js being required: https://github.com/cypress-io/cypress-documentation/pull/5615

ZachHandley commented 9 months ago

So my only issue with this is that Bun is meant to be a direct replacement of NPM. It quite literally works as a drop in replacement for me everywhere I go. Is there a specific thing that's causing this in Cypress? Bun has replacement features for almost everything, and it has node webserver and such built in, so can there be compatibility added? I'd be happy to peek at it.

jonnalley commented 9 months ago

@ZachHandley agreed with your point. However, in my own mind that seems to give more credence to what I was saying in my prior comment, which is that this is actually a bun issue since 1.0.017. See the link in my prior comment to the GitHub issue in Bun’s repo.

ZachHandley commented 9 months ago

@ZachHandley agreed with your point. However, in my own mind that seems to give more credence to what I was saying in my prior comment, which is that this is actually a bun issue since 1.0.017. See the link in my prior comment to the GitHub issue in Bun’s repo.

For the record, my Dockerfile is actually not based on oven/bun https://github.com/ZachHandley/invoiceninja/blob/v5-stable/Dockerfile I was running the Bun install script and then running those commands from an Ubuntu base image, but maybe you are correct. I see that issue, but it doesn't seem to point to anything specific, re2 and firebase something?

Just trying to help InvoiceNinja out by dockerizing the application entirely with all deps

MikeMcC399 commented 9 months ago

@jonnalley

However, in my own mind that seems to give more credence to what I was saying in my prior comment, which is that this is actually a bun issue since 1.0.017. See the link in my prior comment to the GitHub issue in Bun’s repo.

With no Node.js installed, execute the following:

bun init --yes
bun add cypress --save-dev --ignore-scripts
export DEBUG=cypress:*
bun cypress install

This fails with

TypeError: undefined is not an object

MikeMcC399 commented 9 months ago

@ZachHandley

For the record, my Dockerfile is actually not based on oven/bun https://github.com/ZachHandley/invoiceninja/blob/v5-stable/Dockerfile I was running the Bun install script and then running those commands from an Ubuntu base image, but maybe you are correct.

An Ubuntu base image would not normally have Node.js installed by default.

In any case the environment to reproduce the issue is now clear (no Node.js installed) and it does not require Docker to reproduce.

MikeMcC399 commented 9 months ago

The Bun / Node.js compatibility page says:

Bun aims for complete Node.js API compatibility. Most npm packages intended for Node.js environments will work with Bun out of the box; the best way to know for certain is to try it.

This page is updated regularly to reflect compatibility status of the latest version of Bun. The information below reflects Bun's compatibility with Node.js v20. If you run into any bugs with a particular package, please open an issue. Opening issues for compatibility bugs helps us prioritize what to work on next.

I don't normally use Bun, so I wouldn't want to open a Bun issue. Perhaps somebody who is interested in using Cypress with Bun could open a Bun issue, so that the compatibility is looked at? In the meantime you will need to have Node.js installed.

Edit: I didn't see any Bun user reporting the compatibility issue with the Cypress postinstallation script, and since I had already done the work to reproduce the issue, I decided after all to report it to Bun myself.

The comment (above) that Node.js is required still stands.

MikeMcC399 commented 9 months ago

@ZachHandley

MikeMcC399 commented 8 months ago
MikeMcC399 commented 7 months ago

In https://github.com/cypress-io/cypress/issues/28722#issuecomment-1908494774 @jennifer-shehane clarified that Node.js is required to install Cypress and this is also now listed in the Cypress documentation under System requirements.

At this time, Bun has implemented only a subset of Node.js as listed on Bun > Node.js compatibility.

Attempting to download the Cypress binary fails with only Bun installed and no Node.js installed. This is the subject of this issue. It seems that the failure occurs when Cypress tries to verify the checksum of the downloaded cypress.zip Cypress binary file. Although it is possible to work around this issue by downloading and unzipping the Cypress binary file into the Cypress cache by hand, this is not helpful overall because other incompatibilities still prevent Cypress from running. See issue https://github.com/cypress-io/cypress/issues/28962.

MikeMcC399 commented 5 months ago

@ZachHandley

Please re-test as it seems that bun has resolved this issue in bun v1.1.8 which was released on May 10, 2024.

dinuta commented 5 months ago

I tested yesterday both on windows and linux with bun v1.1.8 around 200 e2e tests with cypress. The UI is written with quasar dev framework (vue js based).

  1. bun install
  2. quasar dev
  3. cypress run (PASS)

So from my point of view it works.

dinuta commented 5 months ago

The command bun test does not work but at this moment the flow described at my previous post is sufficient.

image

MikeMcC399 commented 5 months ago

@dinuta

dinuta commented 5 months ago

Hi @MikeMcC399 ,

Seems like npm is still required, and this seems not a full support for cypress. Let me present you the Dockerfile I use:

FROM oven/bun:1.1.8-alpine

ENV APP_DIR /home/node/app

WORKDIR $APP_DIR

COPY ./ $APP_DIR

RUN apk add --update npm
RUN bun install --yarn
RUN bun install -g @quasar/cli

RUN quasar build
RUN chmod 744 /home/node/app/start.sh

ENTRYPOINT ["/home/node/app/start.sh"]
MikeMcC399 commented 5 months ago

@dinuta

hammzj commented 5 months ago

I'm having issues with this as well:

5.913 [SUCCESS]  Downloaded Cypress     
5.913 [STARTED] Task without title.
5.913 
5.913 75 |         };
5.913 76 |         const unzipFallback = _.once(unzipWithNode);
5.913 77 |         const unzipWithUnzipTool = () => {
5.913 78 |           debug('unzipping via `unzip`');
5.913 79 |           const inflatingRe = /inflating:/;
5.913 80 |           const sp = cp.spawn('unzip', ['-o', zipFilePath, '-d', installDir]);
5.913                           ^
5.913 TypeError: Executable not found in $PATH: "unzip"
5.913  code: "ERR_INVALID_ARG_TYPE"
5.913 
5.913       at spawn (node:child_process:710:15)
5.913       at node:child_process:2:41
5.913       at unzipWithUnzipTool (/usr/src/app/node_modules/cypress/lib/tasks/unzip.js:80:22)
5.913       at /usr/src/app/node_modules/cypress/lib/tasks/unzip.js:147:20
5.913       at /usr/src/app/node_modules/yauzl/index.js:37:7
5.913       at /usr/src/app/node_modules/yauzl/index.js:141:16
5.913       at /usr/src/app/node_modules/yauzl/index.js:631:5
5.913       at /usr/src/app/node_modules/fd-slicer/index.js:32:7
5.913       at node:fs:294:107
5.913 

Is unzip part of node-js as well?

MikeMcC399 commented 5 months ago

@hammzj

MikeMcC399 commented 5 months ago

Note that the Cypress Docker images provide all the prerequisites for installing and running Cypress in a Docker container. They are however configured with Node.js, so this is not a solution if the requirement is to run in an environment with no Node.js installed.

hammzj commented 5 months ago

@MikeMcC399 Funny enough, we're not trying to use a Cypress image. Our issue is related to Bun installing Cypress unintentionally for our main app containers. Even though Cypress is an optional/dev dependency, it's still being installed as part of the web app container. Thus, we just need to get through unzipping Cypress so it doesn't fail when building images needed for our internal servers. I know there's likely two issues going on there that need some more investigation but we just want to get this working in the meantime. However, this seemed to work:

RUN apt-get update -y && apt-get upgrade -y RUN apt-get install -y unzip

I also looked at these images that bundle Bun and node together but we ran into separate issues there: https://github.com/ImBIOS/bun-node

MikeMcC399 commented 5 months ago

@hammzj

Thanks for confirming that adding unzip to your Docker image solves the installation issue!

I believe that it should be possible to close this issue now.

jonnalley commented 5 months ago

In my container installing unzip also works for me with bun 1.1.8

hammzj commented 5 months ago

This should probably be denoted somewhere in the Cypress docs if it makes sense.

MikeMcC399 commented 5 months ago

@hammzj

This should probably be denoted somewhere in the Cypress docs if it makes sense.

You're free to make this suggestion in the https://github.com/cypress-io/cypress-documentation repo, however you should consider that Cypress does not support or document the use of Bun at this time.

The Cypress documentation lists Node.js as a prerequisite in the System requirements section and this is sufficient to install Cypress without unzip being installed. What won't work is if neither unzip nor Node.js are installed.

hammzj commented 5 months ago

Returning to this. So, I got it to work locally with bun, but the cypress.io GH Action will not work with bun.

There's no support in it for bun, so no matter what, this error will be given immediately if only bun install is used:

Action failed. Missing package manager lockfile. Expecting one of package-lock.json (npm), pnpm-lock.yaml (pnpm) or yarn.lock (yarn) in working-directory ...

Due to https://github.com/cypress-io/github-action/blob/65a304c3ceca767ae029124625699e9a76b05201/index.js#L109-L120

MikeMcC399 commented 5 months ago

@hammzj

hammzj commented 5 months ago

Nice! I didn't know about that @MikeMcC399 . Thanks for the information on that!

MikeMcC399 commented 4 months ago

I suggest to close this issue, since there is nothing in Cypress preventing Cypress being installed in a Docker container with Bun.

If you use a Bun Docker container such as oven/bun:debian then you need to install the Debian package unzip.

This is also the case for Cypress Docker images. See cypress-io/cypress-docker-images > factory/factory.Dockerfile which is used to build Cypress Docker images:

    # Needed by cypress installation 'unzip.js' script
    unzip

In this case the set of Dockerfile commands to install Cypress will run successfully:

WORKDIR /opt/app
RUN bun init
RUN bun add cypress -D
RUN bun cypress install
RUN bun cypress verify

Note that this does not solve the separate issue of Cypress failing to run under Bun without Node.js. Bun would still need to fill the API gaps for this to work. (See https://bun.sh/docs/runtime/nodejs-apis for Bun's list of implemented, partially implemented and unimplemented Node.js methods.)

MikeMcC399 commented 4 months ago

@hammzj

This should probably be denoted somewhere in the Cypress docs if it makes sense.

The Cypress documentation Getting Started > Installing Cypress > System requirements > Docker prerequisites has been updated to spell out the need for Node.js and the recommendation to install unzip in any Docker image. Cypress Docker images already fulfil these requirements.

Thank you for your suggestion!