cypress-documentation icon indicating copy to clipboard operation
cypress-documentation copied to clipboard

Cypress tsconfig.json configuration with `"type": "module"`?

Open MikeMcC399 opened this issue 9 months ago • 2 comments

Description

What would you like?

Document how to set up Cypress with TypeScript when package.json contains "type": "module".

Why is this needed?

Tooling > TypeScript states that Cypress tests can be written in TypeScript and includes a section Configure tsconfig.json.

The Node.js type field in package.json can be defined as module, commonjs or left undefined. If the field type is defined as module, then .js files are treated as CommonJS.

Other

According to https://www.typescriptlang.org/docs/handbook/modules/reference.html#the-module-compiler-option

node16 and nodenext are the only correct module options for all apps and libraries that are intended to run in Node.js v12 or later, whether they use ES modules or not.

Using the following in tsconfig.json appears to work

"compilerOptions": {
"module": "nodenext" /* Specify what module code is generated. */
}

however I don't have experience in TypeScript to want to be the author of a documentation change.

  • Also https://github.com/cypress-io/cypress-documentation/issues/5262 is still open and waiting for an experienced TypeScript user to update the documentation to cover Cypress non-legacy (Cypress 10 and above) use with TypeScript.

MikeMcC399 avatar Jan 13 '25 15:01 MikeMcC399