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

'spec.cy.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module. #23062

Closed
bryanltobing opened this issue Aug 2, 2022 · 1 comment
Labels
CT Issue related to component testing existing workaround

Comments

@bryanltobing
Copy link

bryanltobing commented Aug 2, 2022

Current behavior

The error happened when I configured cypress with typescript and ran type check using npx tsc --noEmit --incremental false

Desired behavior

There's no error

Test code to reproduce

I use nextjs.

and based on this example https://github.com/vercel/next.js/tree/canary/examples/with-cypress they solved it by adding export {}
to every cypress.ts file which I think is ugly and can be easily forgotten.
https://github.com/vercel/next.js/blob/cd3e054f14ce38f4ff57c727a997da2a6e1d05dd/examples/with-cypress/cypress/e2e/app.cy.ts#L22-L23

My project can be tested here https://github.com/bryantobing12/next-boilerplate/tree/feat/cypress

  • pnpm install
  • pnpm type:check

The error will appear

Cypress Version

10.3.1

Other

What I have tried:

@cypress-bot cypress-bot bot added the stage: investigating Someone from Cypress is looking into this label Aug 2, 2022
@cypress-bot cypress-bot bot added stage: routed to ct and removed stage: investigating Someone from Cypress is looking into this labels Aug 5, 2022
@rockindahizzy rockindahizzy added the CT Issue related to component testing label Aug 5, 2022
@rockindahizzy rockindahizzy removed their assignment Aug 9, 2022
@ZachJW34
Copy link
Contributor

ZachJW34 commented Oct 6, 2022

@bryantobing12 to work around this, you could exclude all of the cypress files from your tsconfig.json, and then run separate npx tsc -p cypress/tsconfig.json --noEmit process to typecheck your Cypress files.

Unfortunately, there is nothing we can do to get rid of this error as cypress tests are not structured in such a way that makes the isolatedModules flag happy.

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 existing workaround
Projects
None yet
Development

No branches or pull requests

4 participants