fix(ts-templates): allow esbuild + unrs-resolver install scripts for tsx#831
Draft
DaveHanns wants to merge 1 commit into
Draft
fix(ts-templates): allow esbuild + unrs-resolver install scripts for tsx#831DaveHanns wants to merge 1 commit into
DaveHanns wants to merge 1 commit into
Conversation
npm 11 introduced an allowlist gate for dependency lifecycle scripts. When a
freshly scaffolded TypeScript template is installed with npm 11+, npm skips
the postinstall scripts of `esbuild` (a transitive dependency of `tsx`) and
`unrs-resolver`, printing:
npm warn allow-scripts esbuild@... (postinstall: node install.js)
npm warn allow-scripts unrs-resolver@... (postinstall: node postinstall.js)
esbuild's postinstall is what downloads its native binary, so skipping it
leaves `node_modules/esbuild/bin/esbuild` missing and any `tsx src/main.ts`
run (including `npm start` / `apify run`) fails. The obvious remedy
(`npm approve-scripts esbuild unrs-resolver`) does not work on a fresh
install because the packages are not yet installed:
npm error code ENOMATCH
npm error No installed packages match: esbuild, unrs-resolver
Declaring `trustedDependencies` in package.json opts these two packages
into running their install scripts, which is exactly what a working `tsx`
requires. This is applied to every `ts-*` template that ships `tsx`.
Surfaced during an evaluation of Apify surfaces for agent-driven Actor development.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
npm 11 introduced an allowlist for dependency lifecycle scripts. Freshly scaffolded TypeScript templates run
tsx src/main.ts(vianpm start/apify run), andtsxdepends transitively onesbuild, whose native binary is fetched by apostinstallscript. Under npm 11+ that script is silently skipped, sotsxfails at runtime.This PR adds a two-entry
trustedDependenciesallowlist to everyts-*template soesbuildandunrs-resolverare permitted to run their install scripts.Reproduction (before this PR)
The obvious workaround (
npm approve-scripts esbuild unrs-resolver) does not work on a fresh install — the packages have not yet been installed, so approve-scripts errors out:That produces a chicken-and-egg situation where the user has to run
npm installtwice (once with--ignore-scripts=falseafter manual approval, etc.), which is friction they should not have to discover.Fix
Add to each
templates/ts-*/package.json:This is npm 11's opt-in mechanism for pre-approving lifecycle scripts of specific packages. It is inert on older npm versions (which already run all install scripts by default), so it is safe for the templates'
engines.node: >=18support range.Applied to all 14 templates that ship
tsx:Test plan
apify create tmp -t ts-empty && cd tmp && npm installcompletes without anynpm warn allow-scriptslines foresbuild/unrs-resolver.node_modules/esbuild/bin/esbuild --versionworks.apify run(ornpm start) launches withouttsxerroring on missing esbuild binary.trustedDependenciesis ignored there).Follow-up (not in this PR)
Once base images track Node 22+ / 24+,
start:devcould migrate fromtsxtonode --experimental-strip-types src/main.tsand drop thetsx+esbuilddependency chain entirely.Surfaced during an evaluation of Apify surfaces for agent-driven Actor development.