-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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.config.ts does not work with ESM: "exports is not defined in ES module scope" #23552
Comments
I'd expect this to work, too. We should fix this. Thanks for the excellent bug report. |
Can you share a minimal reproduction? It's likely a configuration error - the error isn't very insightful, but I can help you fix it once I know your setup. |
@oliviervanbulck (or anyone else coming here) you might want to also see #24111 which has some common solutions to this issue (usually type=module conflicting with the defaults in |
Can't share a reproduction, but I am also having the issue of a newly installed Running Node both 18.14, tried 16.19 and |
I can confirm that
Resolve the issue |
I can confirm that we have exactly the same issue when setting type:module in package.json. Maybe someone could explain why changing |
If you use a If you are using In this case, we use The conditional logic to decide which loader we use is here. In your case, I suspect the issue is related to your Alternatively, you can do a {
// Most ts-node options can be specified here using their programmatic names.
"ts-node": {
// It is faster to skip typechecking.
// Remove if you want ts-node to do typechecking.
"transpileOnly": true,
"compilerOptions": {
// compilerOptions specified here will override those declared below,
// but *only* in ts-node. Useful if you want ts-node and tsc to use
// different options with a single tsconfig.json.
"module": "ES2015", // <==== added this, so it will compile to ES modules, not CommonJS
}
}
} The reason this stuff is so confusing is many projects have a single I hope this comment clarifies a bit around what's actually happening, and helps fix your issue. Let me know if you've got any other ongoing issues. |
Proposed fixes do not work for me, I don't want to remove |
I am getting this with Cypress 13.12.0, using the default generated file in a scaffolded Vue app (using Vite).
{
"extends": "@tsconfig/node20/tsconfig.json",
"include": [
"vite.config.*",
"vitest.config.*",
"cypress.config.*",
"nightwatch.conf.*",
"playwright.config.*"
],
"compilerOptions": {
"composite": true,
"noEmit": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"module": "ESNext",
"moduleResolution": "Bundler",
"types": ["node"]
}
}
import { defineConfig } from 'cypress';
export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
}); My Changing the file to a |
Current behavior
I would expect Cypress to work out of the box with TypeScript and ESM:
"type": "module"
inpackage.json
The following
tsconfig.json
:The following
cypress.config.ts
:However, with that setup, Cypress currently fails with the following error:
Desired behavior
Cypress should work with this setup.
Test code to reproduce
Clone https://github.com/nwalters512/cypress-esm-typescript-config, then run
yarn && yarn cypress
. Observe the following error message:Cypress Version
10.6.0
Node version
16.13.0
Operating System
macOS 12.5
Debug Logs
The text was updated successfully, but these errors were encountered: