-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
tsc type definition conflicts, duplicate identifiers in @types/mocha chai etc #7435
Comments
Hey @ericblade - we're still sorting out the best practices for ensuring globals in type definitions among various dependencies don't conflict. Can you try adding a {
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["cypress"]
}
} and in your base "types": [
"react",
"mocha",
] /* Type declaration files to be included in compilation. */, and see if that helps with the issues you're describing? |
Sure, I can try that. If that works, I'm hoping that some other fix can be located though -- i just setup this project so that all my tests are side-by-side with the code, which is a common thing to do (the tests run in both node and cypress, i have some files in |
OK, so, doing the change that you suggest works all the way through build and test in 4.5.0. Then I upgrade to 4.6.0, and build works (previously it was what generated the large error stream), after I comment out one test that is outside the So, apparently, it's not just the build failing phase that is causing the hang during Neither version of The change to the |
@ericblade Could you run Cypress in debug mode mode and print the entire set of logs here when it hangs during |
Sorry, I actually see now you gave us the project.
Is this during I haven't been able to recreate any hanging behavior in 4.6.0 from the project provided. Could you be more specific on how to replicate this behavior? Thanks! |
Sure, I just cloned it to test that it's happening on a fresh install. Clone my repo, upgrade cypress in the package.json, npm install, npm run cypress:run Here's as much output as I was able to grab from setting DEBUG=cypress:*
It hangs at this point, and just keeps repeating the process_profiler messages approximately every 20-30 seconds or so. |
These messages
give me some pause. They don't occur during my regular build process, only apparently when Cypress is building. I feel like there's some sort of interaction happening here between the version of mocha in use in my project (for running tests in node) and the version of mocha in use inside cypress. I've also witnessed a problem with this specific project, with attempting to install mocha >= 6.0 causes cypress to fail, as well, and that was with the older version of cypress. But, I have no problem with the older version of cypress and my current repository, only 4.6.0 is showing this problem. I don't really have any idea what that error means, to be able to try to diagnose it. |
Hmm. Seems that guess may have been right -- removing the mocha directory from my local node_modules causes all the tests to run in cypress:run, although they now all fail because there is no version of mocha available to import. This is a curious issue, and I'm maybe wondering if there's some basic architecture issues at play with attempting to have both node tests using node, and browser tests using cypress. Keeping in mind, I don't really understand exactly how cypress works -- is cypress bundling it's own mocha and chai and other modules into the code that it runs? So then attempting to also bundle my local version of it, ends up with conflicting modules with the same name? That makes me curious what the difference is between 4.5 and 4.6 that makes the problem significantly worse. Before 4.6, I could do this, but I couldn't upgrade my mocha >= 6.0. With 4.6, I can't even get cypress run to work when I have the webpack-processor enabled. |
So, to summarize my working assumption, which may be wrong, but I think the data supports it -- when using the webpack-processor, cypress is jamming two different versions of the same mocha/chai modules into my code, a version supplied by cypress, and a version supplied by my repo. For some reason, this either didn't happen in 4.5.0, or it happened in a way that it's effects didn't prevent cypress from functioning. Does that make sense? Is there some way we could seek to support a use-case such as this? Perhaps a "do not bundle cypress mocha" option somewhere? I'd prefer to explicitly import my requirements anyway. |
I'm having a similar issue, but with JQuery types! CORRECTION: the app builds correctly, it's cypress that reports some errors but ultimately works aniway Small section of the logs:
|
That does look to be similar in nature of the issue, it's just not producing fatal conflicts like mine appears to be. Since I'm not an expert in cypress (just started using it, really, don't know much at all about it's internals), I'm hoping someone who is can confirm or deny my suspicions above.. if confirm, i wonder if it would be a good idea to (optionally?) not jam mocha, chai, jquery, any other libs that are being added in (again, if that's what's happening), in favor of relying on the user to have those installed as peer dependencies. |
4.7.0 fixes the aspect of the test suite freezing. I am able to build my project with the workaround given earlier .. i guess if i want to continue on this path, i'll probably have to follow The Cypress Way :) and move my tests to the cypress directory instead of having them side-by-side with the code. (or figure out a way to get typescript to ignore my test files except when testing..) I think this mostly covers it though. not sure if i should close this, or if there's any further actionable items here to look into? |
@jennifer-shehane I see you added the "existing workaround" label to this issue... can you please share what that workaround is?
BTW, while I'm not sure it's relevant, I'm also using |
@jrnail23 what worked for me was putting a separate tsconfig in the cypress directory, which lists cypress in it's types config, and removing cypress from the tsconfig in the root directory. I still have suspicion that the entire methodology going on here might have some flaws, that that doesn't address though, but no one has addressed my suspicions above so far. |
Thanks for the tip, @ericblade, but no dice for me. My problem isn't actually related to running my tests -- that works just fine, believe it or not. |
right, that's where my problem was as well. My project uses tsc as a type-checker before it runs building with webpack and friends. That step failed, when I removed cypress from the project root types, and put it only in the cypress directory, then it works. perhaps you might need to add the cypress directory to your exclusions in tsconfig? |
See this message for specifics #7435 (comment) |
OK, so I realize I neglected to mention that my project is actually a package of Cypress plugins that uses cypress to test them. So I can't remove I have a {
"extends": "../../tsconfig.base",
"compilerOptions": {
"lib": ["es2018", "dom"],
"outDir": "./dist",
"rootDir": "./src",
"types": ["cypress", "node"]
},
"include": ["src"],
"references": [{ "path": "../testing-server-core/tsconfig.build.json" }]
} I've got a separate {
"extends": "./tsconfig.build",
"compilerOptions": {
"composite": false,
"rootDir": ".",
"types": ["cypress", "node", "chai-subset", "dirty-chai"]
},
"include": ["src", "test"]
} Again, this worked fine in versions 4.5 and below -- it stopped working in v4.6. #7435 (comment) |
UPDATE: I was able to get my typechecking to work by getting rid of chai-subset and dirty-chai. I can live without them, but it would be nice to be able to use chai plugins as advertised. I assume that since they both augment chai's interfaces, they were probably including their own chai types dependencies, conflicting with the ones bundled by Cypress. So I suppose there's your test case going forward -- to be able to support chai plugins in typescript. 😅 |
Still having this issue, did anyone found a solution that is not a hack? Thanks. |
So we too are finding this issue, with cypress 7.x. It should also be noted, just merely installing the cypress 7.x dep, gives us these type errors. Even when there are no cypress based tests. |
6.x and 7.x don't work for me for a myriad of reasons that i haven't bothered to try to pick apart, so i'm unfortunately no further help :| |
My workaround for chai-subset is to uninstall /**
* This is copied from `@types/chai-subset`. The types package imports
* `@types/chai` which conflicts with Cypress' definitions for chai which is why
* this code is copied instead of installing that package.
*/
declare module "chai-subset" {
global {
namespace Chai {
interface Assertion {
containSubset(expected: any): Assertion
}
interface Assert {
containSubset(val: any, exp: any, msg?: string): void
}
}
}
const chaiSubset: Chai.ChaiPlugin
export = chaiSubset
} I'm not sure it's really necessary for /// <reference types="chai" /> |
This should no longer be happening in the latest Cypress. If this is still an issue in the latest Cypress version, please open a new report with a reproducible example. |
Project is https://github.com/ericblade/quagga2
Project has it's own dependency on
@types/mocha
@types/chai
declared. This is so editor support for typescript works correctly.Running
tsc
on the project in the build step fails with duplicate definitions.On top of that, since this is also causing typescript compilation to fail, when I run 'cypress run', which uses
webpack-preprocessor
to package, cypress just hangs indefinitely, when I would expect it to fail.Running
cypress open
does not fail, as for speed reasons, I have configured open to not usewebpack-preprocessor
.Reverting to 4.5.0 corrects the issues, and all tests run as normal.
Version of
webpack-preprocessor
doesn't seem relevant -- I tried both 5.2.1 which is what I used prior to the 4.6.0 upgrade, and 5.4.1, which was the recommended upgrade with cypress 4.6.0.The text was updated successfully, but these errors were encountered: