Skip to content

module: add module.entrypoint - #64903

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:module-entrypoint
Open

module: add module.entrypoint#64903
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:module-entrypoint

Conversation

@mcollina

@mcollina mcollina commented Aug 1, 2026

Copy link
Copy Markdown
Member

Adds module.entrypoint to node:module: the resolved URL string of the entry point of the current thread.

The semantics follow require.main and import.meta.main (thread-scoped): inside a worker thread it is the URL of the script the worker was started with, not the entry point of the process. This complements #64800, which exposes the process-wide entry point inherited by workers.

  • Works regardless of whether the entry point is CommonJS or ESM.
  • undefined for --eval, the REPL, STDIN input, and eval: true workers; set to the data: URL for data URL workers.
  • The value is fully resolved: extension searching is applied and symlinks are followed (unless --preserve-symlinks-main), so it matches require.main.filename / the entry point's import.meta.url rather than process.argv[1].

Refs: #51840
Refs: #64800

Add `module.entrypoint`, a property exposing the resolved URL of the
entry point of the current thread. Unlike `require.main`, it works
regardless of whether the entry point is a CommonJS or an ECMAScript
module, and inside worker threads it reflects the entry point of the
worker itself, matching the semantics of `require.main` and
`import.meta.main`.

Refs: nodejs#51840
Refs: nodejs#64800
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. labels Aug 1, 2026
@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.15%. Comparing base (a7d16a8) to head (b6075b5).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64903      +/-   ##
==========================================
+ Coverage   90.13%   90.15%   +0.01%     
==========================================
  Files         746      746              
  Lines      242893   242925      +32     
  Branches    45769    45777       +8     
==========================================
+ Hits       218935   219006      +71     
+ Misses      15444    15399      -45     
- Partials     8514     8520       +6     
Files with missing lines Coverage Δ
lib/internal/main/worker_thread.js 94.37% <100.00%> (+0.01%) ⬆️
lib/internal/modules/helpers.js 98.96% <100.00%> (+0.02%) ⬆️
lib/internal/modules/run_main.js 97.71% <100.00%> (+0.06%) ⬆️
lib/module.js 100.00% <100.00%> (ø)

... and 25 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants