cypress-io / cypress

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

`yarn cypress open` does not open Cypress with yarn v2 #6377

Open gvdp opened 4 years ago

gvdp commented 4 years ago

Current behavior:

Not sure if this really has to do with yarn (v2) but adding the latest cypress version to a project fails for me. It successfully installs when I use npm.

Stacktrace:

➤ YN0000: ┌ Link step
➤ YN0007: │ cypress@npm:4.0.0 must be built because it never did before or the last one failed
➤ YN0009: │ cypress@npm:4.0.0 couldn't be built successfully (exit code 1, logs can be found here: /var/folders/4r/fbk_4j8d3ss5xl8975901nhr0000gp/T/logfile-6119EAzUDTs6CGBm.log)

Content of logfile-6119EAzUDTs6CGBm.log:


# This file contains the result of Yarn building a package (cypress@npm:4.0.0)
# Script name: postinstall

/.../test-cypress/.yarn/cache/any-observable-npm-0.3.0-4832f4f3ed-1.zip/node_modules/any-observable/register.js:29
        throw new Error('Cannot find any-observable implementation nor' +
        ^

Error: Cannot find any-observable implementation nor global.Observable. You must install polyfill or call require("any-observable/register") with your preferred implementation, e.g. require("any-observable/register")('rxjs') on application load prior to any require("any-observable").
    at loadImplementation (/..../test-cypress/.yarn/cache/any-observable-npm-0.3.0-4832f4f3ed-1.zip/node_modules/any-observable/register.js:29:9)
    at /...../test-cypress/.yarn/cache/any-observable-npm-0.3.0-4832f4f3ed-1.zip/node_modules/any-observable/loader.js:30:18
    at Object.<anonymous> (/..../test-cypress/.yarn/cache/any-observable-npm-0.3.0-4832f4f3ed-1.zip/node_modules/any-observable/index.js:2:39)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.module_1.Module._load (/..../test-cypress/.pnp.js:15569:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/..../test-cypress/.yarn/cache/@samverschueren-stream-to-observable-npm-0.3.0-3da2ac7de0-1.zip/node_modules/@samverschueren/stream-to-observable/index.js:2:20)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.module_1.Module._load (/..../test-cypress/.pnp.js:15569:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)

Desired behavior:

A succesfull install

Test code to reproduce

New folder yarn init yarn add --dev cypress@4.0.0

Versions

yarn : 2.0.0-rc.27 cypress: 4.0.0 OS: macOS Catalina 10.15.3

jenkshields commented 4 years ago

I ran into this - it seems like an error with a dependency relying on an older version of rxjs. Installing rxjs and rxjs-compat seems to work around this.

CypressCecelia commented 4 years ago

@gvdp can you confirm if the workaround provided by @jenkshields fixed your issue?

huvber commented 4 years ago

I can add that in my case install the dependencies will allow to avoid that error but if you run

yarn cypress open

the binary starts but the window doesn't show. The only way to see the window is to run

npx cypress open
jennifer-shehane commented 4 years ago

I'm not able to recreate the installation error with Cypress 4.0.2 (or 3.8.3) and yarn 2.

 yarn add cypress
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 3.37s
➤ YN0000: ┌ Fetch step
➤ YN0013: │ which@npm:2.0.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wrap-ansi@npm:3.0.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wrappy@npm:1.0.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yauzl@npm:2.10.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yauzl@npm:2.4.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed in 7.11s
➤ YN0000: ┌ Link step
➤ YN0007: │ cypress@npm:4.0.2 must be built because it never did before or the last one failed
➤ YN0000: └ Completed in 1.75s
➤ YN0000: Done in 12.23s

I am able to recreate the 'hanging' when running yarn cypress open. I have to manually force quit the Cypress process

Debug logs:

 DEBUG=cypress:* yarn cypress open
  cypress:cli:cli cli starts with arguments ["/Users/jennifer/.nvm/versions/node/v12.8.1/bin/node","/Users/jennifer/Dev/yarn-test/.yarn/unplugged/cypress-npm-4.0.2-9b440563c1/node_modules/cypress/bin/cypress","open"] +0ms
  cypress:cli NODE_OPTIONS=--require /Users/jennifer/Dev/yarn-test/.pnp.js +0ms
  cypress:cli:cli program parsing arguments +1ms
  cypress:cli:cli opening Cypress +1ms
  cypress:cli parsed cli options {} +175ms
  cypress:cli opening from options {"project":"/Users/jennifer/Dev/yarn-test"} +0ms
  cypress:cli command line arguments ["--project","/Users/jennifer/Dev/yarn-test"] +0ms
  cypress:cli verifying Cypress app +0ms
  cypress:cli checking environment variables +1ms
  cypress:cli checking if executable exists /Users/jennifer/Library/Caches/Cypress/4.0.2/Cypress.app/Contents/MacOS/Cypress +2ms
  cypress:cli Binary is executable? : true +1ms
  cypress:cli binaryDir is  /Users/jennifer/Library/Caches/Cypress/4.0.2/Cypress.app +0ms
  cypress:cli Reading binary package.json from: /Users/jennifer/Library/Caches/Cypress/4.0.2/Cypress.app/Contents/Resources/app/package.json +0ms
  cypress:cli Found binary version 4.0.2 installed in: /Users/jennifer/Library/Caches/Cypress/4.0.2/Cypress.app +2ms
  cypress:cli { verified: true } +3ms
  cypress:cli is Verified ? true +1ms
  cypress:cli needs to start own Xvfb? false +0ms
  cypress:cli spawning, should retry on display problem? false +1ms
  cypress:cli spawning Cypress with executable: /Users/jennifer/Library/Caches/Cypress/4.0.2/Cypress.app/Contents/MacOS/Cypress +2ms
  cypress:cli spawn args [ '--no-sandbox', '--', '--project', '/Users/jennifer/Dev/yarn-test', '--cwd', '/Users/jennifer/Dev/yarn-test' ] { detached: false, stdio: 'inherit' } +0ms
  cypress:ts Running without ts-node hook in environment "production" +0ms
  cypress:server:appdata path: /Users/jennifer/Library/Application Support/Cypress/cy/production/browsers +0ms
  cypress:server:cypress starting cypress with argv [ '/Users/jennifer/Library/Caches/Cypress/4.0.2/Cypress.app/Contents/MacOS/Cypress', '--no-sandbox', '--', '--project', '/Users/jennifer/Dev/yarn-test', '--cwd', '/Users/jennifer/Dev/yarn-test' ] +0ms
  cypress:server:args argv array: [ '/Users/jennifer/Library/Caches/Cypress/4.0.2/Cypress.app/Contents/MacOS/Cypress', '--no-sandbox', '--project', '/Users/jennifer/Dev/yarn-test', '--cwd', '/Users/jennifer/Dev/yarn-test' ] +0ms
  cypress:server:args argv parsed: { _: [ '/Users/jennifer/Library/Caches/Cypress/4.0.2/Cypress.app/Contents/MacOS/Cypress' ], sandbox: false, project: '/Users/jennifer/Dev/yarn-test', cwd: '/Users/jennifer/Dev/yarn-test', invokedFromCli: true } +3ms
  cypress:server:util:proxy found proxy environment variables {} +0ms
  cypress:server:args options { _: [ '/Users/jennifer/Library/Caches/Cypress/4.0.2/Cypress.app/Contents/MacOS/Cypress' ], sandbox: false, project: '/Users/jennifer/Dev/yarn-test', cwd: '/Users/jennifer/Dev/yarn-test', invokedFromCli: true, config: {} } +1ms
  cypress:server:args argv options: { _: [ '/Users/jennifer/Library/Caches/Cypress/4.0.2/Cypress.app/Contents/MacOS/Cypress' ], sandbox: false, project: '/Users/jennifer/Dev/yarn-test', cwd: '/Users/jennifer/Dev/yarn-test', invokedFromCli: true, config: {}, projectRoot: '/Users/jennifer/Dev/yarn-test' } +0ms
  cypress:server:cypress from argv [ '/Users/jennifer/Library/Caches/Cypress/4.0.2/Cypress.app/Contents/MacOS/Cypress', '--no-sandbox', '--project', '/Users/jennifer/Dev/yarn-test', '--cwd', '/Users/jennifer/Dev/yarn-test' ] got options { _: [ '/Users/jennifer/Library/Caches/Cypress/4.0.2/Cypress.app/Contents/MacOS/Cypress' ], sandbox: false, project: '/Users/jennifer/Dev/yarn-test', cwd: '/Users/jennifer/Dev/yarn-test', invokedFromCli: true, config: {}, projectRoot: '/Users/jennifer/Dev/yarn-test' } +5ms
  cypress:server:appdata path: /Users/jennifer/Library/Application Support/Cypress/cy/production +344ms
  cypress:server:cypress starting in mode interactive with options { _: [ '/Users/jennifer/Library/Caches/Cypress/4.0.2/Cypress.app/Contents/MacOS/Cypress' ], sandbox: false, project: '/Users/jennifer/Dev/yarn-test', cwd: '/Users/jennifer/Dev/yarn-test', invokedFromCli: true, config: {}, projectRoot: '/Users/jennifer/Dev/yarn-test' } +120ms
  cypress:server:cypress running Electron currently +26ms
  cypress:server:appdata path: /Users/jennifer/Library/Application Support/Cypress/cy/production +4s
  cypress:server:appdata path: /Users/jennifer/Library/Application Support/Cypress/cy/production/cache +45s

--- Cypress just hangs forever using up 100%+ CPU
Screen Shot 2020-02-28 at 3 33 26 PM
AStoker commented 4 years ago

I had this same issue, but ultimately resolved it. Here's what I found.

  1. I had Yarn 2 installed globally. This is not how Yarn recommends using Yarn 2 (berry). Check out their installation instructions and remove Yarn 2 (if you had it) and install Yarn 1.x globally.

    Installing Yarn 2.x globally is discouraged as we're moving to a per-project install strategy. We advise you to keep Yarn 1.x (Classic) as your global binary by installing it via the instructions you can find here.

  2. Follow their installation instructions and set yarn on your project to use latest (berry) by running yarn set version berry
  3. Add Cypress (latest) yarn add cypress and it should install fine.

That resolves the initial issue. But something else to note in how Cypress works with Yarn 2, it seems that when you run Cypress (npx cypress open), even if you're in the project directory that has your tests, it doesn't load up that project by default, you have to manually select your project.

jennifer-shehane commented 4 years ago

@AStoker Thanks for the followup. This would explain why I was not able to replicate as I did not install Yarn 2 globally as they advise.

We do recommend the workaround in this comment for installing on Yarn 2 https://github.com/cypress-io/cypress/issues/6377#issuecomment-592742158

We will leave this issue open for the yarn cypress open issue however.

Also @AStoker - make sure you do not have cypress globally installed as this is the behavior if you have cypress globally installed - to open Cypress and allow you to select project.

ghost commented 4 years ago

@AStoker @jennifer-shehane Hello, I wasn't able to fix the problem with the steps provided. I have only yarn 1.x installed locally yarn 1.22.0 Here's the list of the commands I've executed to reproduce the issue

mkdir test-project
cd test-project/
yarn init
yarn set version berry
yarn add cypress
yarn cypress open

I've waited for more than a minute and the Cypress window did not appear for me.

My OS details: OS: Ubuntu 18.04 bionic Kernel: x86_64 Linux 5.3.0-40-generic

AStoker commented 4 years ago

@jennifer-shehane, do you have any tips about debugging this (or is somebody already on it)? I'm not afraid to spend a bit of time trying to help identify what is going on (not sure if I'll be able to solve it though, but hey, that's how open source works, everybody together). However, I'm not familiar with how Cypress hooks into the yarn to be run (and therefore listen to any debug statements). Is there a place you'd recommend I start looking?

AStoker commented 4 years ago

Also, if it's any help, I ran yarn cypress open and just left it (forgot about it honestly) and eventually came back about 30 minutes later and found that the window had actually opened up. Nothing was loaded, just had the title bar, but it did actually have something loaded. Edit: Timed it this time, took about 15 minutes for it to open to the empty Cypress window

phjardas commented 4 years ago

I can confirm this problem on my Windows 10 Pro 10.0.18363 machine with the reproduction provided by @DanAtSpark.

AStoker commented 4 years ago

Adding some additional details (and a workaround) for those of you who are on Yarn 2. I haven't been able to figure out exactly how Cypress starts its execution, but I was thinking that potentially the issue was revolving around node trying to identify all the modules required to actually run. Since Yarn 2 doesn't have a node_modules folder and by default uses the PnP setup, I thought that maybe Node was doing what it does when it can't find a library, it goes to the parent directory and looks to see if it has a node_modules folder containing what it needs, and up and up it goes.

So I decided to tell yarn to place the node_modules folder back in the directory by adding the nodeLinker plugin as recommended by the Yarn site. Now, when you run yarn install again, it will place all the node modules back into a folder as in Yarn 1. At this point, when running yarn cypress open it will work as expected.

In the end, I'd still like to figure out what is exactly happening here and get Cypress to run with the default PnP setup.

maxime1992 commented 4 years ago

I think https://github.com/cypress-io/cypress/issues/6378 is a duplicate of this one.

I made a comment here: https://github.com/cypress-io/cypress/issues/6378#issuecomment-614591409 I have the same issue but I'm not using yarn 2.

Removing node_modules, cleaning cypress cache, trying to use cypress 3.6.0 or cypress 4.4.0... Nothing works locally anymore

jennifer-shehane commented 4 years ago

@maxime1992 please see my comment https://github.com/cypress-io/cypress/issues/6378#issuecomment-617552586 - your issue is unrelated to the yarn issue. Upgrade to 4.4.1 to get a fix.

masihjahangiri commented 3 years ago

@AStoker Your solution is temporary and cypress should support built-in yarn 2 (PNP algorithm) and it's really important. We use yarn 2 for the zero-install feature to improve our CI build time, and If we use nodeLinker, we miss that feature. cc: @arcanis Do you have any plan to support cypress?

arcanis commented 3 years ago

cc: @arcanis Do you have any plan to support cypress?

I don't use Cypress myself, so I don't plan to dig into that.

michaelfarrell76 commented 3 years ago

we are attempting to add support in https://github.com/cypress-io/cypress/pull/15623 . we actually got this working with:

FILE_PATH="$RESOURCE_PATH/app/packages/server/lib/util/resolve.js" sed $SED_ARGS "s/resolve.sync.*/require.resolve('typescript', { paths: [projectRoot] })/g" "$FILE_PATH"

echo "done!"

- adding the following deps to the caller package.json:
"graceful-fs": "^4.2.6",
"debug": "^4.3.1",
 "ansi_up": "^5.0.0",
     "bluebird": "^3.7.2",
     "strip-ansi": "^6.0.0",
         "resolve": "^1.20.0",
             "chalk": "^4.0.0",
                 "minimist": "^1.2.5",
                 "cypress": "=6.8.0",


however ive been struggling to get the monkey patch to work with cypress 7.1.0. it would be great to have more help from the cypress team on this one since it requires getting pretty deep into how plugins are registered
elpddev commented 3 years ago

Its seems cypress 6 is working. 7 is not. build hangs forever.

michaelfarrell76 commented 3 years ago

@elpddev thats what we found, we've pinned ourselves to 6 and have a monkey patch to keep it working, very fragile. we attempted to add support in this PR: https://github.com/cypress-io/cypress/pull/15623 but whatever changed in cypress 7 made the problem much worse. havent gotten a chance to check cypress 8 yet

azat-io commented 2 years ago

I works with v6.9.1, but not with v9.2.0 😞

mjhenkes commented 2 years ago

I'm unable to recreate this issue using the steps provided:

mkdir test-project cd test-project/ yarn init yarn set version berry yarn add cypress yarn cypress open

Cypress launches as expected and is able to run tests.

I'm using yarn 3.1.1, node16.5.0, and cypress 9.2.0 on macOS 11.6.2

nalandial commented 2 years ago

For posterity since this issue is quite old: yarn 2/pnp support was officially added in 8.1.0 (release notes). See #8008

@jennifer-shehane Does this issue want to be closed?

mjhenkes commented 2 years ago

I need to amend my previous statement I am able to recreate cypress open failing when using yarn 2.4.3.

mkdir test-project cd test-project/ yarn init yarn set version 2 <--- this sets the version to 2.4.3 yarn add cypress yarn cypress open

Click the todo spec and cypress fails with the following error.

Screen Shot 2022-01-12 at 4 36 51 PM
arcanis commented 2 years ago

yarn set version 2 <--- this sets the version to 2.4.3

Try running yarn set version stable - this problem got fixed in a later release (we're at 3.1.1).

mjhenkes commented 2 years ago

@arcanis, yep, yarn 3.1.1 works fine for me.

delyada commented 2 years ago

Cypress 9.5.1 fixed it for me with yarn 3.2 (which repro'd this issue for me before), with https://github.com/cypress-io/cypress/pull/19792.