Skip to content

Content mappers affected by node execve environment-dropping bugΒ #65334

Closed

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.2 and 7.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 skips execve on Windows).
  • Introduced by Use process.execve where it is supportedΒ typescript-go#3241, which made the tsc wrapper use process.execve instead of execFileSync. Still present on typescript-go main at 89d5d5b.
  • typescript declares engines.node as >=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

  1. added
    Bug
    External
    on Nov 5, 2026
  2. RyanCavanaugh commented on Nov 5, 2026

    @RyanCavanaugh
    Member

    Annoying to have to work around this but the fix is trivial enough we should just do it

  3. changed the title [-]`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[/+] on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugExternal

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions