Skip to content

test: fix esm issue in node-spec-runner#50289

Merged
jkleinsc merged 1 commit intomainfrom
fix-node-spec-runner-package-json
Mar 16, 2026
Merged

test: fix esm issue in node-spec-runner#50289
jkleinsc merged 1 commit intomainfrom
fix-node-spec-runner-package-json

Conversation

@codebytere
Copy link
Copy Markdown
Member

Description of Change

Chromium added a top-level package.json in CL:7485999 that sets the type to module and breaks commonjs tests run via node-spec-runner.js. This commit temporarily changes the type to commonjs while running the tests, then changes it back to module when done.

Errors would occur on every test like the following:

electron on git:main ❯ node script/node-spec-runner.js parallel/test-crypto
=== release test-crypto ===
Path: parallel/test-crypto
file:///Users/codebytere/Developer/electron-gn/src/third_party/electron_node/test/parallel/test-crypto.js:23
const common = require('../common');
               ^

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/Users/codebytere/Developer/electron-gn/src/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///Users/codebytere/Developer/electron-gn/src/third_party/electron_node/test/parallel/test-crypto.js:23:16
    at ModuleJob.run (node:internal/modules/esm/module_job:430:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:661:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)

Node.js v24.14.0
Command: /Users/codebytere/Developer/electron-gn/src/out/Testing/Electron.app/Contents/MacOS/Electron /Users/codebytere/Developer/electron-gn/src/third_party/electron_node/test/parallel/test-crypto.js


[00:00|% 100|+   0|-   1]: Done

Failed tests:
/Users/codebytere/Developer/electron-gn/src/out/Testing/Electron.app/Contents/MacOS/Electron /Users/codebytere/Developer/electron-gn/src/third_party/electron_node/test/parallel/test-crypto.js

Checklist

Release Notes

Notes: none

Chromium added a top-level package.json in CL:7485999 that sets
the type to module and breaks commonjs tests run via
node-spec-runner.js. This commit temporarily changes the type to
commonjs while running the tests, then changes it back to module when done.
@codebytere codebytere added semver/none target/40-x-y PR should also be added to the "40-x-y" branch. target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. labels Mar 16, 2026
@jkleinsc jkleinsc merged commit ffad672 into main Mar 16, 2026
76 checks passed
@jkleinsc jkleinsc deleted the fix-node-spec-runner-package-json branch March 16, 2026 16:55
@release-clerk
Copy link
Copy Markdown

release-clerk Bot commented Mar 16, 2026

No Release Notes

@trop
Copy link
Copy Markdown
Contributor

trop Bot commented Mar 16, 2026

I have automatically backported this PR to "40-x-y", please check out #50294

@trop trop Bot removed the target/40-x-y PR should also be added to the "40-x-y" branch. label Mar 16, 2026
@trop
Copy link
Copy Markdown
Contributor

trop Bot commented Mar 16, 2026

I have automatically backported this PR to "41-x-y", please check out #50295

@trop
Copy link
Copy Markdown
Contributor

trop Bot commented Mar 16, 2026

I have automatically backported this PR to "42-x-y", please check out #50296

@trop trop Bot added in-flight/41-x-y in-flight/42-x-y merged/42-x-y PR was merged to the "42-x-y" branch. merged/41-x-y PR was merged to the "41-x-y" branch. merged/40-x-y PR was merged to the "40-x-y" branch. and removed target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. in-flight/42-x-y in-flight/41-x-y in-flight/40-x-y labels Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/40-x-y PR was merged to the "40-x-y" branch. merged/41-x-y PR was merged to the "41-x-y" branch. merged/42-x-y PR was merged to the "42-x-y" branch. semver/none

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants