-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Cannot consume ES module based cypress config when using Yarn 3 #22747
Comments
Any chance that you've figured out a solution? |
I didn't try yet, but it should be as simple as pointing Cypress at where ever Yarn PNP puts node_modules. Happy to assist with this if you'd like to either take a stab, or even just point me in the direction - I know Cypress well, but not Yarn 3. |
@lmiller1990 Thanks for looking into this, I'm trying to switch a project over to Yarn PNP and cypress is my last hold up. Yarn PNP uses a custom loader and virtual filesystem, so there is not a 'node_modules' to point to. The trick should be to make sure ts-node is using the yarn loader, which is usually accomplished when loading a node script using yarn command eg 'yarn cypress run'. But not working in this case because I suspect the cypress command is spinning off another process to run ts-node? I'm happy to help play around with this if you have some suggestions. Also, I tried renaming my cypress.config.ts file to cypress.config.mts, which should be supported by the latest ts-node, but cypress doesn't like the mts extension yet. |
Not sure where to start with this, I'll need to do some research. I do not think we support |
Probably need to do something around here, not sure what. I think what might be happening is this line is erroneously What would be interesting is to see what happens in a Yarn 3 project without TypeScript - just using regular CJS. If that works, my suspicion is probably correct? cc @rockindahizzy |
Running into a similar issue. Using yarn |
I think I was misleading slightly - the title should not be Basically, yarn 3 + TS isn't working? I think it's because we try to load your local TS from |
Running into the same error with Yarn 3.2.3 and TS during migration from Cypress 9 to 10. Any updates? |
I haven't had a chance to look at this in more depth yet. I'm sorry. I don't think I can look at this during Dec, but I would like to see this triaged and fixed in January. Let me try and bump this one up in priority. |
Hey team! Please add your planning poker estimate with Zenhub @astone123 @lmiller1990 @marktnoonan @mike-plummer @rockindahizzy @warrensplayer @ZachJW34 |
This is the workaround I found to run it with yarn v3 #22699 (comment) |
@gusgard That workaround is not working in my environment. Are you using typescript for your cypress config? |
@lmiller1990 - this might help This remains an issue in Cypress 12.3.0 I have this as well. I think the problem is in the code of ProjectConfigIpc in forkConfigProcess where it launches a plain node instance to do things. As this node instance was not launched via yarn, it does not get the required patching to resolve packages according to the Yarn 2/3 (PNP) rules. If the NODE_OPTIONS were set to require the .pnp-cjs file then it should work. I have not been able to test this because I don't have time to figure out how to build a cypress distribution from source and try it. I also wanted to try it by patching cypress as it was installed on my machine, but the cypress npm dist does not seem to contain this code. I'm happy to help test any proposed solution. And if I can get help in patching the cypress dist as it's installed (via yarn), then I can make the patch and try it. |
This seems to only apply to the webpack-dev-server. Some (including me) are using vite. |
I am experiencing the same issue. I have tried converting it to .js or .mjs but nothing worked. As far as I understand, Cypress is trying to reference the Typescript from the Your configFile is invalid: /home/app/frontend/apps/qualification/cypress.config.ts
It threw an error when required, check the stack trace below:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/app/frontend/apps/qualification/cypress.config.ts
at new NodeError (node:internal/errors:399:5)
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:79:11)
at defaultGetFormat (node:internal/modules/esm/get_format:121:38)
at defaultLoad (node:internal/modules/esm/load:81:20)
at nextLoad (node:internal/modules/esm/loader:163:28)
at ESMLoader.load (node:internal/modules/esm/loader:605:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
at new ModuleJob (node:internal/modules/esm/module_job:64:26)
at #createModuleJob (node:internal/modules/esm/loader:480:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) |
Cypress isn't yet 100% compatible with Yarn 3, plug-n-play mode and typescript. The solution is to use good ol' fashioned JS with its config file. See cypress-io/cypress#22747
Summary: Update Cypress from 9.x to 12.x, and perform all relevant migrations. Changes are the results of [10.0 migration](https://docs.cypress.io/guides/references/migration-guide#Migrating-to-Cypress-100), [11.0 migration](https://docs.cypress.io/guides/references/migration-guide#Migrating-to-Cypress-110), and [12.0 migration](https://docs.cypress.io/guides/references/migration-guide#Migrating-to-Cypress-120) guides. The reason for using `cypress.config.mjs` instead of `cypress.config.ts` is that the latter is not working with Yarn 3 yet ([1](cypress-io/cypress#24209), [2](cypress-io/cypress#22747), [3](cypress-io/cypress#25958)). If that changes, we can revisit. Notably, one of the larger changes is that test isolation is now on by default. This means the page is refreshed between each test rather than each suite, so some tests needed to be reconfigured to work with that paradigm. Cypress' UI has gotten a major refresh as well, so I changed the commands to account for it. Relevant Issues: N/A Type of change: /kind cleanup Test Plan: Follow instructions in `src/ui/cypress/README.md`. In particular, try `yarn run cypress:run:chrome`. All of the tests should pass, totally headlessly. Signed-off-by: Nick Lanam <nlanam@pixielabs.ai>
Cypress isn't yet 100% compatible with Yarn 3, plug-n-play mode and typescript. The solution is to use good ol' fashioned JS with its config file. See cypress-io/cypress#22747
I don't think that is the issue here
It is using the native ESM loader which means the file must be .js to my understanding. What's the minimal setup to repro this, I can take a look. Are you doing |
Edit: I might have gotten a little ahead of myself here, as the following change allowed me to open cypress@13 without that "invalid config file" error. |
If you are using type: module you need to include file extensions for Node.js to resolve the files correctly |
@lmiller1990 i have two do-what-you-want days next week at work and thought about looking into this, do you have any more pointers at where to start or maybe some general advice about this part of the codebase? I have read the overall contributors guideline. |
Hi! I'm not working on Cypress anymore, but I can do my best to point you in the right direction.
The issue I got stuck on was either the symlinks for things like |
I actually think i got something working yesterday, will try and make a PR tomorrow, thanks for the advice anyway and gl with the new job! |
Sure, happy to give your code a test and review if you need it. |
My progress so far: To read the config.ts alone seems to be isolated to a single addition of the pnp node api: But i have run into many other problems when trying to serve an angular app via the webpack-dev-server under pnp. See the error here: I mostly run this command when trying to debug and then run the
I have also tried experimenting with Any general advice or thoughts are welcome @lmiller1990. It took half the day to just be able to navigate around the project - it's quite a beast :) I have some time again tomorrow to look into this. |
It probably doesn't make any difference here, but the stable version of Yarn Modern is now |
I've tried weith yarn4, cypress@13 has an issue with resolving files fron node_modules, cypress@12.17.3 has the following issue
With yarn@3.6.4 no issues |
☝️ I have a NX17 + yarn4 + cypress3 repro https://github.com/vire/nx-17-yarn4-cypress13-repro just git clone, run yarn, and then what you get is
|
Same for me (different modules, failed to find react and ramda)
|
|
@MikeMcC399 That's not a workaround, that's just not using Yarn PnP at all. |
Sorry if the suggestion was not helpful to you. According to other posts I have seen from @lmiller1990 , he has not been working for Cypress.io for several months now. I can't see any feedback in the issue from anybody else in the Cypress.io organization, so I don't know if there are plans to fix the Yarn Plug'n'Play support in Cypress. If Yarn Classic projects are migrated to Yarn Modern they retain If you are using Yarn Modern and you are tied to using |
Again, the issue is not with anyone's flexibility, but with Cypress not supporting a Yarn feature that people go through the trouble of adopting because it's useful. |
I am also hoping that the Cypress.io team will fix this and other issues relating to Yarn Plug'n'Play! |
Does the Cypress team have a plan to fix this? This issue has been open for years. |
Current behavior
Does not work correctly with
cypress.config.ts
containing ES module syntax when using Yarn 3 (does not createnode_modules
). I get an error and cannot proceed.I think the problem is we try to resolve your TS install from
projectRoot
but new versions of yarn install modules in some other place that isn't in<project>/node_modules
.There's a lot of information in this issue, and related ones - before working on this, spend a bit of time reading and understanding the issue. It looks like it is primarily related to Plug n Play feature.
Note: many users are excited for this fix - if you are working it, please build a pre-release binary and share it here, so users can test it out.
Test code to reproduce
https://github.com/lmiller1990/yarn-3-issue-ts
yarn --version
Cypress Version
10.3.0+
Other
Created from #22071 (comment)
The text was updated successfully, but these errors were encountered: