Skip to content

oxnode watch --tsconfig is overridden by TS_NODE_PROJECT from --env-file #876

Closed

Description

@fengmk2

oxnode watch --tsconfig cli.json --env-file=.env main.ts uses the config that TS_NODE_PROJECT in .env names instead of cli.json.

Reproduction

$ cat package.json cli.json env.json .env a/name.ts b/name.ts main.ts
{ "type": "module" }
{ "compilerOptions": { "paths": { "@lib/*": ["./a/*"] } } }
{ "compilerOptions": { "paths": { "@lib/*": ["./b/*"] } } }
TS_NODE_PROJECT=env.json
export const name: string = 'cli.json';
export const name: string = 'env.json';
import { name } from '@lib/name';
console.log('config', name);

$ oxnode watch --tsconfig cli.json --env-file=.env main.ts
[oxnode] watching for changes
config env.json

$ oxnode watch --tsconfig cli.json main.ts
[oxnode] watching for changes
config cli.json

Reproduced on main (4759ced, v1.0.0) with Node.js 22.18 on macOS arm64. Found while embedding the watcher in Vite+ for vpx watch (voidzero-dev/vite-plus#3164).

Cause

tsconfigEnv() passes --tsconfig as OXC_TSCONFIG_PATH and removes TS_NODE_PROJECT from the child's environment. Node.js then loads the env file, which adds TS_NODE_PROJECT back, and the binding reads TS_NODE_PROJECT before OXC_TSCONFIG_PATH.

Possible fix

Set TS_NODE_PROJECT to the same path instead of removing it. Node.js keeps a variable the environment already has (FOO=env node --env-file=x.env keeps env when the file sets FOO=file), so the env file can no longer override the choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions