Skip to content
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

Merged
merged 2 commits into from Jan 16, 2024

Conversation

AtofStryker
Copy link
Contributor

@AtofStryker AtofStryker commented Jan 12, 2024

… 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 (via type: 'module'), Cypress sets the module to commonjs when registering ts-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 run commonjs with ease. This however started being a problem when new moduleResolution properties were introduced to newer versions of typescript that are incompatible with commonjs.

To avoid this issue, this PR sets the moduleResolution to node to guarantee commonjs as a module configuration will work. #26308 attempted to fix this in a similar way, except the moduleResolution setting to node happened behind to TS_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 with ts-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 the next.js reproduction steps in #27731 to create a new next.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 for next.js@14, mentioned in #28185.

PR Tasks

Copy link

cypress bot commented Jan 12, 2024

7 flaky tests on run #53534 ↗︎

0 5728 98 0 Flakiness 7

Details:

Update cli/CHANGELOG.md
Project: cypress Commit: fb894df074
Status: Passed Duration: 14:50 💡
Started: Jan 16, 2024 3:48 PM Ended: Jan 16, 2024 4:03 PM
Flakiness  scaffold-component-testing.cy.ts • 1 flaky test • launchpad-e2e

View Output

Test Artifacts
scaffolding component testing > vuecli4vue3 > scaffolds component testing for Vue CLI 4 w/ Vue 3 project Test Replay Screenshots
Flakiness  commands/querying/querying.cy.js • 1 flaky test • 5x-driver-chrome

View Output

Test Artifacts
... > intercept aliases > returns null if no xhr is found Test Replay
Flakiness  e2e/origin/origin.cy.ts • 1 flaky test • 5x-driver-chrome

View Output

Test Artifacts
cy.origin > withBeforeEach > passes runnable state to the secondary origin on retry Test Replay
Flakiness  cypress/cypress.cy.js • 3 flaky tests • 5x-driver-chrome

View Output

Test Artifacts
... > correctly returns currentRetry Test Replay
... > correctly returns currentRetry Test Replay
... > correctly returns currentRetry Test Replay
Flakiness  e2e/origin/snapshots.cy.ts • 1 flaky test • 5x-driver-chrome

View Output

Test Artifacts
cy.origin - snapshots > e2e log verification > Does not take snapshots of XHR/fetch requests from secondary origin if the wrong origin is visited / origin mismatch, but instead the primary origin (existing behavior) Test Replay

Review all test suite changes for PR #28709 ↗︎

… cypress process to make sure value is compatible with commonjs (which is already forced). [run ci]
@AtofStryker AtofStryker force-pushed the fix/set_module_resolution_with_commonjs branch from 7d295fa to c6e0050 Compare January 16, 2024 14:43
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).
Copy link
Collaborator

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

Copy link
Contributor Author

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?

Copy link
Collaborator

@jordanpowell88 jordanpowell88 left a 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

cli/CHANGELOG.md Outdated Show resolved Hide resolved
@AtofStryker AtofStryker merged commit 81fce0e into develop Jan 16, 2024
122 of 128 checks passed
@AtofStryker AtofStryker deleted the fix/set_module_resolution_with_commonjs branch January 16, 2024 17:09
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jan 17, 2024

Released in 13.6.3.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v13.6.3, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jan 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to compile TypeScript with "moduleResolution": "bundler" option in v5
3 participants