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: pass --no-experimental-require-module for node 20.19.0+ versions #31308

Merged
merged 3 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ _Released 3/25/2025 (PENDING)_
- Upgraded `@cypress/request` from `3.0.7` to `3.0.8`. Addressed in [#31311](https://github.com/cypress-io/cypress/pull/31311).
- Upgraded `systeminformation` from `5.21.7` to `5.22.8`. Addressed in [#31281](https://github.com/cypress-io/cypress/pull/31281).

**Bugfixes:**

- Applies a fix from [#30730](https://github.com/cypress-io/cypress/pull/30730) and [#30099](https://github.com/cypress-io/cypress/pull/30099) related to Node.js turning on ESM flags by default in Node.js version `20.19.0`. Fixed in [#31308](https://github.com/cypress-io/cypress/pull/31308).


## 14.2.0

_Released 3/12/2025_
Expand Down
8 changes: 4 additions & 4 deletions packages/data-context/src/data/ProjectConfigIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,18 @@ export class ProjectConfigIpc extends EventEmitter {
// @see Node.js Loader API https://nodejs.org/api/esm.html#customizing-esm-specifier-resolution-algorithm
let tsNodeEsmLoader = `--experimental-specifier-resolution=node --loader ${tsNodeEsm}`

// in nodejs 22.7.0, the --experimental-detect-module option is now enabled by default.
// starting in nodejs 20.19.0 and 22.7.0, the --experimental-detect-module option is now enabled by default.
// We need to disable it with the --no-experimental-detect-module flag.
// @see https://github.com/cypress-io/cypress/issues/30084
if (this.nodeVersion && semver.gte(this.nodeVersion, '22.7.0')) {
if (this.nodeVersion && (semver.gte(this.nodeVersion, '22.7.0') || semver.satisfies(this.nodeVersion, '>= 20.19.0 < 21.0.0'))) {
debug(`detected node version ${this.nodeVersion}, adding --no-experimental-detect-module option to child_process NODE_OPTIONS.`)
tsNodeEsmLoader = `${tsNodeEsmLoader} --no-experimental-detect-module`
}

// in nodejs 22.12.0, the --experimental-require-module option is now enabled by default.
// starting in nodejs 20.19.0 and 22.12.0, the --experimental-require-module option is now enabled by default.
// We need to disable it with the --no-experimental-require-module flag.
// @see https://github.com/cypress-io/cypress/issues/30715
if (this.nodeVersion && semver.gte(this.nodeVersion, '22.12.0')) {
if (this.nodeVersion && (semver.gte(this.nodeVersion, '22.12.0') || semver.satisfies(this.nodeVersion, '>= 20.19.0 < 21.0.0'))) {
debug(`detected node version ${this.nodeVersion}, adding --no-experimental-require-module option to child_process NODE_OPTIONS.`)
tsNodeEsmLoader = `${tsNodeEsmLoader} --no-experimental-require-module`
}
Expand Down
21 changes: 18 additions & 3 deletions packages/data-context/test/unit/data/ProjectConfigIpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ describe('ProjectConfigIpc', () => {
context('forkChildProcess', () => {
// some of these node versions may not exist, but we want to verify
// the experimental flags are correctly disabled for future versions
const NODE_VERSIONS = ['18.20.4', '20.17.0', '22.7.0', '22.11.4', '22.12.0', '22.15.0']
const NODE_VERSIONS = ['18.20.4', '20.17.0', '20.19.0', '22.0.0', '22.7.0', '22.11.4', '22.12.0', '22.15.0']
const experimentalDetectModuleIntroduced = '22.7.0'
const experimentalRequireModuleIntroduced = '22.12.0'
const minorPatchExperimentalModuleIntroduced = '>= 20.19.0 < 21.0.0'

let projectConfigIpc
let forkSpy
Expand Down Expand Up @@ -84,21 +85,35 @@ describe('ProjectConfigIpc', () => {
},
}))

if (semver.gte(nodeVersion, experimentalDetectModuleIntroduced)) {
if (semver.gte(nodeVersion, experimentalDetectModuleIntroduced) || semver.satisfies(nodeVersion, minorPatchExperimentalModuleIntroduced)) {
expect(forkSpy).to.have.been.calledWith(sinon.match.string, sinon.match.array, sinon.match({
env: {
NODE_OPTIONS: sinon.match('--no-experimental-detect-module'),
},
}))
}

if (semver.gte(nodeVersion, experimentalRequireModuleIntroduced)) {
if (semver.gte(nodeVersion, experimentalRequireModuleIntroduced) || semver.satisfies(nodeVersion, minorPatchExperimentalModuleIntroduced)) {
expect(forkSpy).to.have.been.calledWith(sinon.match.string, sinon.match.array, sinon.match({
env: {
NODE_OPTIONS: sinon.match('--no-experimental-require-module'),
},
}))
}

if (semver.eq(nodeVersion, '22.0.0')) {
expect(forkSpy).to.not.have.been.calledWith(sinon.match.string, sinon.match.array, sinon.match({
env: {
NODE_OPTIONS: sinon.match('--no-experimental-detect-module'),
},
}))

expect(forkSpy).to.not.have.been.calledWith(sinon.match.string, sinon.match.array, sinon.match({
env: {
NODE_OPTIONS: sinon.match('--no-experimental-require-module'),
},
}))
}
})
})

Expand Down