-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
fix: force moduleResolution: 'node' when ts-node is registered in the… #28709
Conversation
… cypress process to make sure value is compatible with commonjs (which is already forced). [run ci]
7d295fa
to
c6e0050
Compare
cli/CHANGELOG.md
Outdated
@@ -4,7 +4,7 @@ | |||
_Released 1/16/2024 (PENDING)_ | |||
|
|||
**Bugfixes:** | |||
|
|||
- Force `moduleResolution` to `node` when `typescript` projects are detected to correctly run Cypress. This change should not have a large impact as `commonjs` is already forced when `ts-node` is registered. Fixes [#27731](https://github.com/cypress-io/cypress/issues/27731). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe worth noting it doesn't work with the esm loader
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe that it doesn't impact it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Doesn't solve every use case but would certainly unblock some users
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
… cypress process to make sure value is compatible with commonjs (which is already forced). [run ci]
Additional details
This PR attempts to fix #27731, which was reopened when #26308 did not resolve the issue.
Currently in Cypress, if a user has
typescript
installed and the project is NOT an ES Module (viatype: 'module'
), Cypress sets the module tocommonjs
when registeringts-node
to load the project's config. This was to guarantee that cypress could run the transpiled config in its owned node process as node can natively runcommonjs
with ease. This however started being a problem when newmoduleResolution
properties were introduced to newer versions of typescript that are incompatible withcommonjs
.To avoid this issue, this PR sets the
moduleResolution
tonode
to guaranteecommonjs
as a module configuration will work. #26308 attempted to fix this in a similar way, except themoduleResolution
setting tonode
happened behind toTS_NODE_COMPILER
flag, which is only set when a user provides a custom compiler, which the Cypress monorepo does here, which made the issue appear to be fixed. This isn't usually set in production, hence why #27731 was opened.This should resolve the issues with
next.js
scaffolding, but e need to figure out a more long term solution to processing the users cypress config with typescript. Right now we use the user's typescript configuration to transpile files executed by the cypress node child process, which is a gamble on compatibility (hence the forcing, but isn't really an option withts-node/esm
due to TypeStrong/ts-node#1997 (comment)).To verify the issue, standalone binaries have been build on the commit in this PR 0481c7a. From testing, it looks like the fix works.
Steps to test
Since reproducing this issue is difficult in the cypress monorepo due to the
TS_NODE_COMPILER
flag set, standalone binaries have been build on the commit in this PR 0481c7a. Follow thenext.js
reproduction steps in #27731 to create a newnext.js
project with the CLI, install cypress, and make sure a user can set up their cypress project for the first time without error and run tests.How has the user experience changed?
next.js@14
with cypress e2e tests and typescript installed should run out of the box. This PR does NOT resolve CT support fornext.js@14
, mentioned in #28185.PR Tasks
cypress-documentation
? (N/A)type definitions
? (N/A)