node icon indicating copy to clipboard operation
node copied to clipboard

fix: prevent V8 tool scripts from being loaded as builtin modules

Open abdulfarid-dev opened this issue 3 weeks ago • 2 comments

This patch prevents Node.js from attempting to load V8 tool scripts under internal/deps/v8/tools/ as builtin modules.

These files are part of V8’s internal tooling and are not valid Node.js builtins. When required or imported with --expose-internals, the loader attempts to treat them as builtin CJS modules, which results in either:

  • SyntaxError: Unexpected token 'export'
    (because the V8 tool scripts contain ESM syntax), or
  • AssertionError in BuiltinLoader::LookupAndCompileFunction
    (data->IsValue()), aborting the process.

This change adds a guard in loadBuiltinModule() to skip any module whose path starts with internal/deps/v8/tools/, and also adds a defensive check to avoid calling compileForPublicLoader() when no builtin module entry exists.

This aligns the behavior with expectations and avoids a crash when users attempt to load these paths with --expose-internals.

Fixes: #60865

abdulfarid-dev avatar Nov 29 '25 15:11 abdulfarid-dev

Review requested:

  • [ ] @nodejs/loaders

nodejs-github-bot avatar Nov 29 '25 15:11 nodejs-github-bot

Yeah, it seems to make more sense to exclude them from the user-accesible list in the first place...

joyeecheung avatar Dec 08 '25 15:12 joyeecheung