Skip to content

Compile createRequire probes for optional addons as deferred refusals - #2015

Open
ctate wants to merge 1 commit into
mainfrom
ctate/compile-createrequire-probes-401dc2
Open

ctate wants to merge 1 commit into
mainfrom
ctate/compile-createrequire-probes-401dc2

Conversation

@ctate

@ctate ctate commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Packages such as pi-tui look for their prebuilt Node-API addons at run
time: a createRequire require call with a computed path, and the
loader's resolve passed as a value, each inside a try block whose catch
takes a fallback. Preflight refused these packages.

Preflight now classifies each use of a createRequire loader. Inside the
try block of a try statement in the same function, a call with a
computed specifier or another argument shape, and resolve or
resolve.paths read as a value, no longer refuse the package. Outside a
try block they keep it refused, with a reason that names the computed
specifier. The loader itself as a value, writes and optional calls stay
refused.

In JavaScript source, such a call evaluates its arguments and then
throws a runtime fence, and the resolve value is a function that throws
one when called, so `(options.resolve ?? require.resolve)(id)` still
calls the option. Both are listed in coverage as deferred to runtime.
TypeScript source keeps the compile-time refusals.

Refs #1777
@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
scriptc Ready Ready Preview, v0 Oct 23, 2026 4:37pm UTC

Comment on lines +2361 to +2369
if (ts.isCallExpression(call) && call.expression === use) {
if (call.questionDotToken) return "escaping";
if (call.arguments.nodes.length === 1 && ts.isStringLiteralLike(call.arguments.nodes[0]!))
return "static";
} else if (!member || isAssignmentTarget7(use)) {
return "escaping";
}
return insideTryBlock7(use) ? "deferred" : "computed";
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Computed require.resolve calls inside a try block are now admitted as deferred, but their statement-level lowering drops argument side effects and can change the fallback result.

Fix on Vercel

This branch was successfully deployed

1 active deployment
Preview — d10ddff5 Deployed Oct 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant