Giter Site home page Giter Site logo

Comments (13)

gnapse avatar gnapse commented on May 18, 2024 2

I hit this issue in a repo that does not have any monorepo/lerna setup. Tried various things from this discussion here and also from the one linked to above in DT, and nothing helped. The only thing that helped was to explicitly install @types/jquery as a dev dependency.

Here's the tsconfig files if that helps:

root tsconfig

{
    "compilerOptions": {
        "noEmit": true,
        "allowJs": true,
        "checkJs": true,
        "target": "es6",
        "moduleResolution": "Node",
        "resolveJsonModule": true,
        "declaration": true,
        "noImplicitReturns": true,
        "jsx": "react",
        "allowSyntheticDefaultImports": true,
        "baseUrl": "."
    },
    "include": ["./src/**/*"],
    "exclude": ["node_modules", "built", "cypress"]
}

cypress/tsconfig.json

{
    "compilerOptions": {
        "strict": true,
        "baseUrl": "../node_modules",
        "target": "es5",
        "lib": ["es5", "dom"],
        "types": ["cypress"]
    },
    "exclude": []
}

from cypress-testing-library.

kentcdodds avatar kentcdodds commented on May 18, 2024 1

Sorry, I don't have the bandwidth to look at this right now. Anyone is welcome to dig a little bit and suggest a solution.

from cypress-testing-library.

gabceb avatar gabceb commented on May 18, 2024

I just experienced the same thing when bumping to the latest version (5.0.2)

from cypress-testing-library.

simjes avatar simjes commented on May 18, 2024

We've had a discussion about this over in the DefinitelyTyped repo DefinitelyTyped/DefinitelyTyped#40099

from cypress-testing-library.

a-b-r-o-w-n avatar a-b-r-o-w-n commented on May 18, 2024

@simjes that thread does not really offer a solid workaround. In my case I had to add the compiler option --skipLibCheck. Not ideal, but gets me past this error.

I wonder if this would be a problem if this package included its own typings instead of hosting the typings on the definitel-typed project? The problem seems to stem from its usage of the global namespace and the typescript compiler's greediness when loading @types/.

Just a thought. I assume there is some historical context for why the types are not co-located with this project.

from cypress-testing-library.

NicholasBoll avatar NicholasBoll commented on May 18, 2024

@a-b-r-o-w-n Do you know if there is a node_modules/@types/cypress in your project? If there is, bad things will happen. There also shouldn't be a node_modules/@types/jquery. If these are present and you don't have either dependencies listed in your package.json, then your IDE (VSCode seems to be the worst offender here) has preemptively installed these types for you.

Cypress had a lot of issues with global/namespace conflicts and chose to not directly require any but instead copy/paste type definitions nested in Cypress type definitions. In most cases, this solved namespace collisions assuming the cypress folder explicitly states that only cypress types should be included in the project.

Type definitions were originally a part of this project, but the source code is not in Typescript so the type definitions were moved to DefinitelyTyped: #68

@types/testing-library__cypress updated to no longer require a specific version of cypress: DefinitelyTyped/DefinitelyTyped#41917

Let us know if you are still running into issues.

from cypress-testing-library.

JochenDiekenbrock avatar JochenDiekenbrock commented on May 18, 2024

I see the same error with @testing-library/cypress version 5.2.1.
There is neither node_modules/@types/cypress nor node_modules/@types/jquery in the monorepo

from cypress-testing-library.

NicholasBoll avatar NicholasBoll commented on May 18, 2024

@a-b-r-o-w-n I updated the reproduction repo a bit by changing the tsconfig.json

File in full:

{
  "compilerOptions": {
    "outDir": "./lib/",
    "module": "commonjs",
    "lib": ["es2015", "dom"],
    "target": "es5",
    "moduleResolution": "node",
    "strict": true,
    "types": ["cypress"],
  },
  "exclude": [
    "node_modules"
  ],
}

Changes:

diff --git a/packages/client/tsconfig.json b/packages/client/tsconfig.json
index dda9816..8bbbb78 100644
--- a/packages/client/tsconfig.json
+++ b/packages/client/tsconfig.json
@@ -2,11 +2,12 @@
   "compilerOptions": {
     "outDir": "./lib/",
     "module": "commonjs",
+    "lib": ["es2015", "dom"],
     "target": "es5",
     "moduleResolution": "node",
     "strict": true,
+    "types": ["cypress"],
   },
-  "include": ["./src/**/*"],
   "exclude": [
     "node_modules"
   ],

I added "types": ["cypress"]. That normally would go into a cypress/ directory since cypress would be the only global you'd want in that directory (to prevent issues with jest or jasmine)

I also added the es2015 lib. That works for Chrome and Firefox which Cypress supports without a runtime transpilation. Also Cypress needs the dom library.

I dropped the include. It was interfering. By default it will include all .ts, .tsx and .d.ts files. You could change it to src/**/* it would also fix the issue.

@JochenDiekenbrock Maybe this could help you as well?

from cypress-testing-library.

JochenDiekenbrock avatar JochenDiekenbrock commented on May 18, 2024

Thank you, @NicholasBoll
The error message in our case is shown when building apps and libs in a (Lerna) monorepo that do not use Cypress at all. There is only one app with Cypress e2e-tests in the monorepo.

Adding "types": ["cypress"] to the apps that do not use Cypress fixes the compile error, but the generated artifacts are different and I'm not sure that they are built correctly. Anyways, having the add the types entry to tsconfigs of other libs/apps does not sound correct.

from cypress-testing-library.

NicholasBoll avatar NicholasBoll commented on May 18, 2024

@JochenDiekenbrock I'm not sure how your monorepo is set up. The project I work on has a base tsconfig that all packages inherit from that has "types": "jest" since all packages use jest.

Only the cypress folder has a tsconfig with "types": "cypress" in it. The Cypress folder is not in any packages

from cypress-testing-library.

NicholasBoll avatar NicholasBoll commented on May 18, 2024

For a more concrete example:

from cypress-testing-library.

raphaelsaunier avatar raphaelsaunier commented on May 18, 2024

I ran into the same issue in a monorepo that uses Yarn Workspaces and where Cypress wasn't installed at the root and where no root tsconfig.json was present.

I got rid of the warning with the same workaround that @gnapse proposed, by adding @types/jquery to the "devDependencies" of the package that is using Cypress.

from cypress-testing-library.

kentcdodds avatar kentcdodds commented on May 18, 2024

This is probably resolved now that the type defs are built-in.

from cypress-testing-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.