-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Cypress fails to run when type is module
#24111
Comments
We had a very similar problem. Ended up with renaming |
@MateusNeres26 thanks, I was able to reproduce it with this project. |
Any update on this? I tried |
FYI: Adding the following line to {
"compilerOptions": {
"module": "ES2015"
}
} My full {
"compilerOptions": {
"target": "ES2015",
"lib": ["ES2019", "DOM"],
"types": ["cypress", "node"],
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,
"noEmit": true,
"module": "ES2015"
},
"include": ["e2e/**/*"]
} |
Hi, I'm also facing this issue while trying to migrate my cypress project to typescript. Any update ? |
@StephaneColson can you share a minimal reproduction? It could be an issue on your end - I'm using Cypress with TS and type=module successfully. |
@lmiller1990 sure With this simple import { defineConfig } from 'cypress';
export default defineConfig({
e2e: {
baseUrl: 'https://myurl.fr/',
},
}); and {
"dependencies": {
"cypress": "^12.3.0",
"typescript": "^4.9.5"
},
"name": "test",
"description": "These end2end tests use [Cypress](https://www.cypress.io/).",
"version": "1.0.0",
"type": "module",
"scripts": {
"test": "npx cypress run"
},
"author": "",
"license": "ISC"
} and {
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"target": "es5",
"lib": ["es5", "dom", "ES2021.String"],
"types": ["cypress", "node"],
"strict": false
},
"include": ["**/*.ts"],
"exclude": ["node_modules"],
} When running
As soon as I remove the My environment:
I tried upgrading to Cypress: 12.6.0 and no improvements! Thanks for your help! |
@StephaneColson I reproduced it. I was able to get it to work by updating tsconfig.json: {
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"module": "ES2015", // <==== added this
"target": "es5",
"lib": ["es5", "dom", "ES2021.String"],
"types": ["cypress", "node"],
"strict": false
},
"include": ["**/*.ts"],
"exclude": ["node_modules"],
} Docs for By default, it's CommonJS for I could be misunderstanding something, but I think this is the correct behavior - |
I saw the comment and tried the trick, but it does not work with my full project...I mean that I have another error I don't know how to fix but now it makes sense. Thanks |
What is the other error? Can you share/reproduce? |
@lmiller1990 Your suggestion fixed it for me. |
It was something not related at all to what is discussed here. Thanks for your help! |
For Cypress with Typescript, we needed to add a `module` option to the root tsconfig (see cypress-io/cypress#24111).
I still had this problem in a project I was upgrading from parcel 1 to Vite, with the newer tsconfig structure (tsconfig, tsconfig.app, tsconfig.node). I tried adding the cypress files to the include of both app and node (individually, not at once) and creating a tsconfig.cypress. While I got a tsconfig.cypress working at one point, my actual project no longer ran, so I reverted the change. The only thing that actually worked was removing type: "module" from package.json. At some point I had an issue that someone had posted a solution to of type: "module", but now the project (and cypress) works fine without that. However, it would be good if there was better information about how to make this work with a main tsconfig that's just references. |
The only things that fixed this for me in a new vite project were: removing The renaming fix actually didn't work for me. Every time I start up cypress after renaming the config file it tries to go through the automated configuration process again and creates a new However, renaming the config file to |
Current behavior
When using typescript and setting type to
module
in package.json cypress fails to run withDesired behavior
Cypress runs
Test code to reproduce
The simplest config you could have like shown here #22795 (comment) or the
cypress.config.ts
can haveCypress Version
10.9.0
Node version
v16.17.1 (fails also with v18)
Operating System
Ubuntu 22.04
Debug Logs
The text was updated successfully, but these errors were encountered: