Skip to content

Conversation

@codebytere
Copy link
Member

@codebytere codebytere commented Oct 22, 2025

Refs:

Electron need to disable source phase imports in renderer and worker processes - Chromium disables them in content/renderer/render_process_impl.cc and the process will hard crash otherwise.

Happy to move this to a different place if there's a better suggestion!

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/config
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Oct 22, 2025
@codebytere codebytere requested a review from guybedford October 22, 2025 09:13
@targos
Copy link
Member

targos commented Oct 22, 2025

Maybe this could be similar to https://github.com/codebytere/node/blob/3bd7d18f84485e97e87fd056ca2820539b60d647/src/node.cc#L761-L766 and expect --no-js-source-phase-imports to be used?

@targos
Copy link
Member

targos commented Oct 22, 2025

btw it looks like source phase imports don't work at all in node, so I'm not sure why they are enabled by default:

> import.source('./test.mjs')
Promise {
  <pending>,
  Symbol(async_id_symbol): 191,
  Symbol(trigger_async_id_symbol): 6
}
> undefined
Uncaught Error [ERR_VM_MODULE_NOT_MODULE]: Provided module is not an instance of Module
    at importModuleDynamicallyWrapper (node:internal/vm/module:526:41) {
  code: 'ERR_VM_MODULE_NOT_MODULE'
}
> node --no-js-source-phase-imports .\imports.mjs
node:internal/modules/esm/module_job:254
        this.module.instantiate();
                    ^
SyntaxError: Source phase import object is not defined for module 'file:///J:/Projects/test/test.mjs'
    at #_instantiate (node:internal/modules/esm/module_job:254:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:369:5)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:691:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5) {
  code: 'ERR_SOURCE_PHASE_NOT_DEFINED'
}

Node.js v25.0.0

@codecov
Copy link

codecov bot commented Oct 22, 2025

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.58%. Comparing base (2fb82c8) to head (7495bbd).
⚠️ Report is 27 commits behind head on main.

Files with missing lines Patch % Lines
src/node.cc 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60364      +/-   ##
==========================================
- Coverage   88.59%   88.58%   -0.01%     
==========================================
  Files         704      704              
  Lines      208474   208401      -73     
  Branches    40067    40054      -13     
==========================================
- Hits       184696   184612      -84     
- Misses      15805    15811       +6     
- Partials     7973     7978       +5     
Files with missing lines Coverage Δ
src/node.cc 76.03% <75.00%> (-0.04%) ⬇️

... and 42 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codebytere
Copy link
Member Author

Oh lol that's fun - i'm happy to just disable it by default again then? cc @GeoffreyBooth

@joyeecheung
Copy link
Member

I think source phase import in Node.js only works with WASM, but not JS.

@targos
Copy link
Member

targos commented Oct 22, 2025

Ok, then I think #60364 (comment) should work

"performance.",
&PerProcessOptions::disable_wasm_trap_handler,
kAllowedInEnvvar);
AddOption("--disable_js_source_phase_imports",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to recognize V8 style negate option --no-js-source-phase-imports, we should declare a --js-source-phase-imports as a V8Option, rather than declaring a standalone --disable....

@legendecas
Copy link
Member

Source phase imports now only work with WASM modules. JS source phase imports are waiting on https://github.com/tc39/proposal-esm-phase-imports.

@ljharb
Copy link
Member

ljharb commented Oct 22, 2025

Indeed, JS source phase imports should be off by default until the feature is stage 3.

Copy link
Contributor

@guybedford guybedford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense. We don't have any snake case flags, perhaps just recase or follow @legendecas's suggestion? Either works for me.

Also I'm pretty sure that this will work with the other codepaths for source phase, but it would be good to check the existing instance phase test to ensure import * as foo from './foo.wasm' still works, by adding this flag to one of those tests in isolation from source phase.

@codebytere codebytere force-pushed the source-phase-imports-disable branch from 3bd7d18 to 8015b0f Compare October 23, 2025 08:03
@codebytere codebytere requested a review from legendecas October 23, 2025 08:03
Copy link
Member

@targos targos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion shouldn't require to add a new option.

@codebytere
Copy link
Member Author

@targos then maybe I'm not clear on what you're suggesting?

@targos
Copy link
Member

targos commented Oct 23, 2025

I'm suggesting to do the same as https://github.com/codebytere/node/blob/3bd7d18f84485e97e87fd056ca2820539b60d647/src/node.cc#L761-L766

Set the flag only if we don't find the --no- prefixed flag in the args.

@codebytere codebytere force-pushed the source-phase-imports-disable branch from 8015b0f to 7495bbd Compare October 23, 2025 08:57
@codebytere codebytere requested a review from targos October 23, 2025 08:57
@codebytere codebytere added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 23, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 23, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@ljharb
Copy link
Member

ljharb commented Oct 23, 2025

JS source phase imports should be disabled by default, though - isn't this keeping the opposite?

@legendecas
Copy link
Member

JS source phase imports should be disabled by default, though - isn't this keeping the opposite?

The --js prefix in the V8 flag is the new prefix of --harmony. --js-source-phase-imports does not enable https://github.com/tc39/proposal-esm-phase-imports.

@ljharb
Copy link
Member

ljharb commented Oct 23, 2025

ah, thanks for explaining :-)

@codebytere codebytere removed the needs-ci PRs that need a full CI run. label Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants