Skip to content

Commit b303c4c

Browse files
fix: pass --no-experimental-require-module for node 20.19.0+ versions (#31308)
* fix: add new node 20 version * docs: improve comments and update test node version --------- Co-authored-by: Jennifer Shehane <[email protected]>
1 parent e0efbd8 commit b303c4c

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

cli/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ _Released 3/25/2025 (PENDING)_
1010
- Upgraded `micromatch` from `4.0.6` to `4.0.8`. Addressed in [#31330](https://github.com/cypress-io/cypress/pull/31330).
1111
- Upgraded `systeminformation` from `5.21.7` to `5.22.8`. Addressed in [#31281](https://github.com/cypress-io/cypress/pull/31281).
1212

13+
**Bugfixes:**
14+
15+
- 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).
16+
17+
1318
## 14.2.0
1419

1520
_Released 3/12/2025_

packages/data-context/src/data/ProjectConfigIpc.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -317,18 +317,18 @@ export class ProjectConfigIpc extends EventEmitter {
317317
// @see Node.js Loader API https://nodejs.org/api/esm.html#customizing-esm-specifier-resolution-algorithm
318318
let tsNodeEsmLoader = `--experimental-specifier-resolution=node --loader ${tsNodeEsm}`
319319

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

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

packages/data-context/test/unit/data/ProjectConfigIpc.spec.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ describe('ProjectConfigIpc', () => {
3838
context('forkChildProcess', () => {
3939
// some of these node versions may not exist, but we want to verify
4040
// the experimental flags are correctly disabled for future versions
41-
const NODE_VERSIONS = ['18.20.4', '20.17.0', '22.7.0', '22.11.4', '22.12.0', '22.15.0']
41+
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']
4242
const experimentalDetectModuleIntroduced = '22.7.0'
4343
const experimentalRequireModuleIntroduced = '22.12.0'
44+
const minorPatchExperimentalModuleIntroduced = '>= 20.19.0 < 21.0.0'
4445

4546
let projectConfigIpc
4647
let forkSpy
@@ -84,21 +85,35 @@ describe('ProjectConfigIpc', () => {
8485
},
8586
}))
8687

87-
if (semver.gte(nodeVersion, experimentalDetectModuleIntroduced)) {
88+
if (semver.gte(nodeVersion, experimentalDetectModuleIntroduced) || semver.satisfies(nodeVersion, minorPatchExperimentalModuleIntroduced)) {
8889
expect(forkSpy).to.have.been.calledWith(sinon.match.string, sinon.match.array, sinon.match({
8990
env: {
9091
NODE_OPTIONS: sinon.match('--no-experimental-detect-module'),
9192
},
9293
}))
9394
}
9495

95-
if (semver.gte(nodeVersion, experimentalRequireModuleIntroduced)) {
96+
if (semver.gte(nodeVersion, experimentalRequireModuleIntroduced) || semver.satisfies(nodeVersion, minorPatchExperimentalModuleIntroduced)) {
9697
expect(forkSpy).to.have.been.calledWith(sinon.match.string, sinon.match.array, sinon.match({
9798
env: {
9899
NODE_OPTIONS: sinon.match('--no-experimental-require-module'),
99100
},
100101
}))
101102
}
103+
104+
if (semver.eq(nodeVersion, '22.0.0')) {
105+
expect(forkSpy).to.not.have.been.calledWith(sinon.match.string, sinon.match.array, sinon.match({
106+
env: {
107+
NODE_OPTIONS: sinon.match('--no-experimental-detect-module'),
108+
},
109+
}))
110+
111+
expect(forkSpy).to.not.have.been.calledWith(sinon.match.string, sinon.match.array, sinon.match({
112+
env: {
113+
NODE_OPTIONS: sinon.match('--no-experimental-require-module'),
114+
},
115+
}))
116+
}
102117
})
103118
})
104119

0 commit comments

Comments
 (0)