cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.69k stars 3.16k forks source link

typescript with esm does not work with certain `tsconfig.json` values #28696

Open AtofStryker opened 8 months ago

AtofStryker commented 8 months ago

Current behavior

Cypress is unable to run typescript/esm projects when certain values are set in the tsconfig.json. This tsconfig.json does not work with ESM when setting type: "module" in the package.json.

{
    "compilerOptions": {
      "target": "es5",
      "lib": ["dom", "dom.iterable", "esnext"],
      "allowJs": true,
      "skipLibCheck": true,
      "strict": true,
      "forceConsistentCasingInFileNames": true,
      "noEmit": true,
      "esModuleInterop": true,
      "module": "es6",
      "moduleResolution": "node",
      "resolveJsonModule": true,
      "isolatedModules": true,
      "jsx": "preserve",
      "incremental": true,
      "plugins": [{ "name": "next" }],
      "paths": { "@/*": ["./*"] }
    },
    "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
    "exclude": ["node_modules"]
  }

To workaround this issue, either comment out allowJs or bump the target to ES6 or greater

Desired behavior

Cypress should be able to run ESM with typescript regardless of the values in my tsconfig.json

Test code to reproduce

https://github.com/AtofStryker/module_reprod_ts

Cypress Version

13.6.2

Node version

v18.15.0

Operating System

macOS 13.5.1 intel

Debug Logs

Useful for debugging:

DEBUG=cypress:lifecycle:ProjectConfigIpc,cypress:server:register-ts-node,cypress:config:addToCypressConfig,cypress:lifecycle:child:run_require_async_child*,cypress:config:addToCypressConfigPlugin npx cypress open


### Other

_No response_
AtofStryker commented 8 months ago

This is identical to the tsconfig.json found in the nextjs@14 scaffolding besides the module and moduleResolution. The same issue would still apply if type: "module" were configured for https://github.com/cypress-io/cypress/issues/27731 reproduction.

cypress-app-bot commented 2 months ago

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.