Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Your application tried to access bluebird, but it isn't declared in your dependencies." When using Component Testing with Yarn PnP #26567

Closed
Teajey opened this issue Apr 23, 2023 · 27 comments
Labels
CT Issue related to component testing

Comments

@Teajey
Copy link

Teajey commented Apr 23, 2023

Current behavior

When running Cypress Component Testing with interactive GUI in a Yarn PnP project

Screenshot 2023-04-23 at 09 46 30

Your application tried to access bluebird, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.

Required package: bluebird Required by: packages/config/src/project/

Require stack:

./packages/config/src/project/utils.ts

Stack trace:
Error: Your application tried to access bluebird, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.

Required package: bluebird
Required by: packages/config/src/project/

Require stack:
- ./packages/config/src/project/utils.ts
    at Function._resolveFilename (/[REDACTED]/.pnp.cjs:61592:13)
    at PackherdModuleLoader._tryResolveFilename (evalmachine.:1:737331)
    at PackherdModuleLoader._resolvePaths (evalmachine.:1:734152)
    at PackherdModuleLoader.tryLoad (evalmachine.:1:732195)
    at customRequire (:4692:1332670)
    at m (:4170:5423)
    at L (:4170:9567)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async T.buildBaseFullConfig (:4383:60987)
    at async T.getFullInitialConfig (:4383:62436)
    at async T.setupNodeEvents (:4383:56576)

Desired behavior

It should continue as expected without error.

It looks like the package @packages/config doesn't declare bluebird in it's dependencies, and Yarn PnP's strictness requires that it is.

Test code to reproduce

Follow these steps in an empty directory:

yarn init -y
yarn set version berry
yarn add cypress vite react react-dom
yarn cypress open

Click 'Component Testing'

Create a 'React.js/Vite' project, click 'Next step'

Hopefully the dev dependencies are detected, although I found at first that they weren't and I had to click 'Skip'

Configuration files are added, press 'Continue'

I've also found that the 'Initializing config...' screen hangs for a long time. Long enough that I end up closing and re-running yarn cypress open, and returning to Component Testing, where it then proceeds as expected.

At this point you should see the same page as the screenshot above.

Cypress Version

12.10.0

Node version

16.18.0

Operating System

macOS Ventura 13.0.1

Debug Logs

No response

Other

I'm not sure if there's a temporary workaround for this. I don't think @packages/config can be referenced by Yarn's packageExtensions setting, since it doesn't seem to be a normal part of the dependency tree

@lmiller1990
Copy link
Contributor

Thanks for the bug report - I was able to reproduce this. A few PRs have landed recently for better Yarn 3 support - hopefully we can get to a point where it all just works.

Made #26570 to hopefully fix this, I'll post a pre-release binary here soon so you can give it a test without waiting for the next release.

@lmiller1990
Copy link
Contributor

I tried adding bluebird as a dep on the off chance it would work, but it didn't. I'm just going to convert the code to use a native Promise.

@lmiller1990
Copy link
Contributor

I removed Bluebird: #26570

@lmiller1990
Copy link
Contributor

Ah, but now I end up with the same problem in another package. I think we need another option - bluebird is used in at least 64 files on the server, refactoring those out is probably impractical. And if not Bluebird, we probably hit this without another module.

I wonder if we need to do something specific for Yarn 3? I have other projects using Yarn 3 that work just fine though - I wonder what's the difference.

@Ckrill
Copy link

Ckrill commented Apr 24, 2023

In case this helps @lmiller1990, I have been running Yarn 3 with Cypress for some time now, and this issue just showed up when upgrading cypress from 12.9.0 to 12.10.0. In fact downgrading to 12.9.0 works just fine for me. ✌️

@nagash77 nagash77 added the CT Issue related to component testing label Apr 24, 2023
@AlexandreBonaventure
Copy link

Same @Ckrill I've been using Cypress with Yarn Pnp since at least cypress@8.x without any issues (just using a esbuild preprocessor).
As a workaround for now, you can add bluebird to your project dependencies, in case it will help others

@jordanpowell88
Copy link
Collaborator

Same @Ckrill I've been using Cypress with Yarn Pnp since at least cypress@8.x without any issues (just using a esbuild preprocessor).
As a workaround for now, you can add bluebird to your project dependencies, in case it will help others

@Teajey does this solution work for you?

@Teajey
Copy link
Author

Teajey commented Apr 24, 2023

Thanks for the quick and detailed response!

Adding bluebird to dependencies does get rid of the error, but I end up with another error I can't find a solution to:

Screenshot 2023-04-24 at 14 35 37

I'm unfortunately not familiar with using esbuild preprocessors. Is this a custom one, or one that I can find online, .e.g: https://github.com/bahmutov/cypress-esbuild-preprocessor ?

@AlexandreBonaventure
Copy link

@Teajey I'm using this one but both should be equivalent: https://github.com/sod/cypress-esbuild-preprocessor#readme
You should give it a try esbuild is super fast for compiling specs, and support Yarn pnp out of the box since v0.15 see https://github.com/evanw/esbuild/releases/tag/v0.15.0

@lmiller1990
Copy link
Contributor

In case this helps @lmiller1990, I have been running Yarn 3 with Cypress for some time now, and this issue just showed up when upgrading cypress from 12.9.0 to 12.10.0. In fact downgrading to 12.9.0 works just fine for me. ✌️

Oh, I did not realize this broken in Cy 12.10. Is that the same for you @Teajey?

We added some code to correctly integrate with PnP in Cy 12.10:

Correctly detect and resolve dependencies when configuring Component Testing in projects using Yarn's Plug'n'Play feature. Fixes #25960.

It looks like this actually exposed more problems than it solved. I wonder if we need more work to correctly support Yarn 3.

I do not think esbuild-preprocessor will help with the current issue @Teajey is encountering - preprocesses are only used for loading the specs, you aren't even getting that far.

@Teajey
Copy link
Author

Teajey commented Apr 25, 2023

This is my first time attempting to use component testing with PnP. I was encountering the dependency issue, so I waited for 12.10. I can't speak for <12.10

@AlexandreBonaventure
Copy link

@lmiller1990 Also, I must say: we're not using using CT at all, so I can only speak for regular e2e testing

@lmiller1990
Copy link
Contributor

Gotcha... thanks, seems like Yarn 3 is more negatively impacted by the "fix" we added.

I won't be able to fix this in the next version (12.10) but we can try to get something done for the following one. I'll post updates here.

@zaq42
Copy link

zaq42 commented Apr 27, 2023

Confirming that this still occurs in 12.11.0.
Looking forward to the fix; we're pinned to 12.9.0 for now.

@warrensplayer warrensplayer removed their assignment Apr 27, 2023
@lmiller1990
Copy link
Contributor

lmiller1990 commented May 1, 2023

I'm not sure how to fix this one yet, I don't have the bandwidth to work on this right now. I'll try to get some 👀 on it soon. I wish Yarn 3 was not so difficult to integrate with. Is there any kind of --force flag we can use to work around this in the meantime?

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented May 5, 2023

A similar issue also exists with E2E testing, Cypress 12.11.0. I will try to add E2E steps to reproduce.

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented May 5, 2023

Steps to reproduce:

Ubuntu 22.04
Node.js 18.16.0

mkdir cy-yarn-pnp
cd cy-yarn-pnp
npm install yarn@latest -g
yarn set version berry # finds and installs 3.5.1
yarn init -y
yarn add cypress@latest -D -E
yarn cypress open

Note error

[27596:0505/140027.512:ERROR:node_bindings.cc(279)] Most NODE_OPTIONs are not supported in packaged apps. See documentation for more details.

Cypress v12.11.0 App opens
In Cypress App select E2E Testing
Click Continue

Cypress App now hangs at "Initializing config..."

Kill the app and start again with

yarn cypress open

image


On Windows 11 the error looks slightly different:

image

(PnP is the default mode for Yarn Modern)

Edit: Confirmed also reproducible in Cypress 12.12.0

@MikeMcC399
Copy link
Contributor

@PilotConway
Copy link

I'm wondering if bluebird just needs to be added to the config package here, since its imported and used in that utils file:

"dependencies": {
"@babel/core": "^7",
"@babel/parser": "^7",
"@babel/plugin-syntax-typescript": "^7",
"@babel/plugin-transform-typescript": "^7",
"@babel/traverse": "7.15.4",
"@babel/types": "^7",
"check-more-types": "2.24.0",
"common-tags": "1.8.0",
"debug": "^4.3.4",
"fs-extra": "^9.1.0",
"lodash": "^4.17.21",
"recast": "0.20.4",
"return-deep-diff": "0.4.0"
},
. Seems like that wouldn't break any dependency tree things since cypress cli itself already requires bluebird.

I tried to pull the cypress repo and test the change locally, but using yarn link I actually can't reproduce the bug to see if that would do it to make a PR and I have to bail on testing this for now. If I get time next week I might try again.

@lmiller1990
Copy link
Contributor

I tried adding bluebird to that package, it does not fix the error: #26570

Yarn 3 has what feels like an endless list of compatibility issues with many libraries.

@MikeMcC399
Copy link
Contributor

Is it time to move away from the 3 year old bluebird? https://github.com/petkaantonov/bluebird#introduction

image

@lmiller1990
Copy link
Contributor

Moving away from Bluebird is a pretty big lift - we use a lot of things without 1:1 mappings, like Bluebird.mapSeries, Bluebird.try, etc.

Even if we did move away from it, I suspect we hit the same issue with a different dependency - it just happens to be Bluebird right now, since that's probably the first dependency that get required'd.

@MikeMcC399
Copy link
Contributor

@lmiller1990

@MikeMcC399
Copy link
Contributor

This issue no longer occurs with Cypress 12.13.0.

Cypress 12.13.0 CT with Yarn Plug'n'Play and vite is however broken (no dependency detection, config file not found).

@zaq42
Copy link

zaq42 commented May 26, 2023

Confirmed... for our E2E testing, I've unpinned 12.9.0 and we are happily using 12.13.0.

Thanks for the effort!

@MikeMcC399
Copy link
Contributor

@Teajey

What do you think about closing this issue though since the bluebird error no longer occurs in Cypress 12.13.0?

@Teajey
Copy link
Author

Teajey commented May 26, 2023

What do you think about closing this issue though since the bluebird error no longer occurs in Cypress 12.13.0?

If the error described in this issue no longer occurs then yeah, I think it makes sense to close it 👍

@Teajey Teajey closed this as completed May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CT Issue related to component testing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants