Repository navigation
Description
π Search Terms
process.execve, environment variables, PATH, content mapper, TS18099, executable file not found in $PATH, runExternalCode
π Version & Regression Information
- Affects
typescript@7.0.2and7.1.0-beta, on Node.js 22.15.0β22.21.0, 23.11.x, and 24.0.0β24.9.0 (macOS and Linux; the wrapper skipsexecveon Windows). - Introduced by Use process.execve where it is supportedΒ typescript-go#3241, which made the
tscwrapper useprocess.execveinstead ofexecFileSync. Still present on typescript-gomainat 89d5d5b. typescriptdeclaresengines.nodeas>=16.20.0, so these Node.js versions are supported.
β― Playground Link
No response
π» Code
npm i typescript@7.1.0-beta
mkdir -p node_modules/m
echo '{"name":"m","version":"1.0.0","typescript":{"contentMapper":{"exec":["node","m.js"]}}}' > node_modules/m/package.json
echo 'process.exit(1)' > node_modules/m/m.js
echo '{"contentMappers":[{"package":"m","extensions":[".x"]}],"include":["a.x"]}' > tsconfig.json
touch a.x
# Run with each Node.js binary directly (`npx node@<version>` goes through a shim)
node node_modules/typescript/bin/tsc --runExternalCode --noEmitπ Actual behavior
On Node.js 22.21.0 and 24.9.0, the native compiler starts with an empty environment, so it cannot find node:
error TS18099: The content mapper 'm' could not be initialized.
The content mapper command 'node' could not be started: exec: "node": executable file not found in $PATH
Environment-based settings such as TS_CONTENT_MAPPER_DEBUG=1 are also ignored.
π Expected behavior
The compiler inherits the environment, as on Node.js 22.21.1 and 24.10.0. There, node starts and the stub mapper exits as written:
error TS18099: The content mapper 'm' could not be initialized.
The content mapper process exited before responding to the 'initialize' request (exit code 1).
Additional information about the issue
The wrapper calls process.execve(exe, [exe, ...process.argv.slice(2)]) without env. env is documented to default to process.env, but before nodejs/node#60029 Node.js passed an empty environment when it was omitted. The fix shipped in v22.21.1, v24.10.0, and v25.0.0.
The environment loss reproduces without TypeScript:
// probe.mjs
process.execve(process.execPath, [process.execPath, '-p', 'process.env.PATH']);node probe.mjs prints undefined on 22.21.0 and 24.9.0, and the inherited PATH on 22.21.1 and 24.10.0.
On Node.js 22.21.0, both of these also start node: running the native binary directly, and the same wrapper with process.env passed as the third argument.
Suggested fix, which behaves the same as today on fixed Node.js versions:
process.execve(exe, [exe, ...process.argv.slice(2)], process.env);
Activity
RyanCavanaugh commentedon Nov 5, 2026
Annoying to have to work around this but the fix is trivial enough we should just do it
[-]`tsc` drops all environment variables on Node.js 22.15β22.21.0 and 24.0β24.9, so content mappers cannot start `node`[/-][+]Content mappers affected by node execve environment-dropping bug[/+]