Skip to content

Invalid types when adding Cypress support #32930

@comatory

Description

@comatory

Current Behavior

After adding a Cypress configuration to a library, using documentation instructions, Typescript errors are raised when running typecheck target.

Expected Behavior

Running typecheck target should pass.

GitHub Repo

https://github.com/productboardlabs/nx-cypress-typecheck-bug

Steps to Reproduce

  1. pnpm dlx create-nx-workspace@latest
  2. Select React stack.
  3. Framework None
  4. No React Router
  5. Vite for bundler
  6. Vitest for tests
  7. Test runner: Cypress
  8. CSS for default styles
  9. Eslint: yes
  10. Prettier: yes
  11. No coding agent
  12. No CI provider
  13. No remote cache
  14. pnpm add @nx/cypress
  15. pnpm nx g @nx/js:library libs/feature
  16. Select vite bundler, eslint and vitest
  17. pnpm nx g @nx/cypress:configuration, select @nx-cypress-typecheck-bug/feature, use vite as bundler, eslint, @nx-cypress-typecheck-bug/feature:serve target, port 3000
  18. pnpm nx sync
  19. Run pnpm nx typecheck feature

You will see errors

Nx Report

Node           : 22.15.0
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 10.17.1

nx                     : 21.6.2
@nx/js                 : 21.6.2
@nx/eslint             : 21.6.2
@nx/workspace          : 21.6.2
@nx/cypress            : 21.6.2
@nx/devkit             : 21.6.2
@nx/eslint-plugin      : 21.6.2
@nx/module-federation  : 21.6.2
@nx/react              : 21.6.2
@nx/rollup             : 21.6.2
@nx/vite               : 21.6.2
@nx/web                : 21.6.2
typescript             : 5.9.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/eslint/plugin
@nx/vite/plugin
@nx/cypress/plugin
---------------------------------------
Cache Usage: 0.00 B / 46.04 GB

Failure Logs

cypress/e2e/app.cy.ts:8:8 - error TS2551: Property 'login' does not exist on type 'cy & CyEventEmitter'. Did you mean 'log'?

8     cy.login('[email protected]', 'myPassword');
         ~~~~~

  ../node_modules/.pnpm/[email protected]/node_modules/cypress/types/cypress.d.ts:1567:5
    1567     log(message: string, ...args: any[]): Chainable<null>
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'log' is declared here.

cypress/support/commands.ts:13:9 - error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations.

13 declare global {
           ~~~~~~

cypress/support/commands.ts:24:22 - error TS2345: Argument of type '"login"' is not assignable to parameter of type 'keyof Chainable<any>'.

24 Cypress.Commands.add('login', (email, password) => {

Package Manager Version

[email protected]

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

Metadata

Metadata

Labels

priority: highHigh Priority (important issues which affect many people severely)scope: testing toolsIssues related to Cypress / Jest / Playwright / Vitest support in Nxtype: bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions