Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cypress + Vite 5 + Typescript: exports is not defined in ES module scope #30313

Closed
NormalCrazy000 opened this issue Sep 28, 2024 · 5 comments
Closed

Comments

@NormalCrazy000
Copy link

NormalCrazy000 commented Sep 28, 2024

Current behavior

When I try to start cypress in a vite 5 project with typescript the console returns this error:
Screenshot 2024-09-29 190429

I think it is due to cypress having problems with the tsconfig.json structure created by vite.
I added cypress.config.ts inside include in tsconfig.app.josn, but even putting it in tsconfig.node.json the result does not change.
The 3 tsconfigs you will find I did not create, but are the basic vite react configuration (npm create vite@latest my-vue-app -- --template react-ts ). I just created the cypress setup with npx cypress open and, right away, the error appeared that referred to the cypress configuration.

Desired behavior

I would like to be able to run cypress in a newly created vite 5 project

Test code to reproduce

Repo

https://github.com/NormalCrazy000/vite5-Cypress.git

Steps to replicate

  1. npm install
  2. npx cypress open

Cypress Version

13.15.0

Node version

18.19.1

Operating System

Windows

Debug Logs

No response

Other

No response

@MikeMcC399
Copy link
Contributor

@NormalCrazy000

You can try the suggestion from that issue and add the following directly to the top of tsconfig.json (or use "module": "ESNext" which vite is already using in the other tsconfig files for app and node):

  "compilerOptions": {
    "module": "ES2015"
  }

tsconfig.json would be then:

{
  "compilerOptions": {
    "module": "ESNext"
  },
  "files": [],
  "references": [
    { "path": "./tsconfig.app.json" },
    { "path": "./tsconfig.node.json" }
  ]
}

An alternative workaround is to rename cypress.config.ts to cypress.config.js.

@NormalCrazy000
Copy link
Author

Thank you very much, add module worked. Sorry for the repetition.

@MikeMcC399
Copy link
Contributor

@NormalCrazy000

Thank you very much, add module worked.

It's good to hear that the configuration worked for you!

Sorry for the repetition.

No problem!

You should be able to close this issue now using the button below ⬇️

@iacullo-atri
Copy link

I don't believe this issue should be closed, as this issue indicates that cypress will not accept the TypeScript configuration from any tsconfig files unless they are named specifically tsconfig.json.

Shouldn't it read the configuration from tsconfig.node.json if that file references it in its files or includes sections?

@ThnxFredrik
Copy link

I agree with @iacullo-atri, adding "module": "ESNext" feels like a hack. Can't we specify which tsconfig to use for Cypress?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants