codebytere

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

Merged
Created: Mar 16, 2026, 8:57:36 AM
Merged: Mar 16, 2026, 11:55:03 AM
4 comments
Target: main

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

Backports

40-x-y
Merged
PR Number
#50294
Merged At
Mar 16, 2026, 3:13:31 PM
Released In
Not yet
Release Date
Not yet
41-x-y
Merged
PR Number
#50295
Merged At
Mar 16, 2026, 2:44:41 PM
Released In
Not yet
Release Date
Not yet
42-x-y
Merged
PR Number
#50296
Merged At
Mar 16, 2026, 1:51:19 PM
Released In
v42.0.0-alpha.2
Release Date
Mar 16, 2026, 7:09:29 PM

Semver Impact

Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.

Semantic Versioning helps users understand the impact of updates:

  • Major (X.y.z): Breaking changes that may require code modifications
  • Minor (x.Y.z): New features that maintain backward compatibility
  • Patch (x.y.Z): Bug fixes that don't change the API
  • None: Changes that don't affect using facing parts of Electron