privatenumber / tsx

⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js
https://tsx.is
MIT License
9.77k stars 154 forks source link

`--env-file` reads commented-out lines of file! #662

Closed zsiegel92 closed 1 month ago

zsiegel92 commented 1 month ago

Acknowledgements

Minimal reproduction URL

https://github.com/zsiegel92/tsx_env_var_bug_mwe

Problem & expected behavior (under 200 words)

The .env file in the MWE repo looks like this:

ENV_VAR=right # comment after
# ENV_VAR=wrong

Using npx tsx --env-file .env test.ts, the commented-out wrong variable is set during execution rather than the correct one. The conditions for this are:

Bugs are expected to be fixed by those affected by it

Compensating engineering work will speed up resolution and support the project

privatenumber commented 1 month ago

This is not a tsx bug—it doesn't implement this feature. All unrecognized flags are just relayed to the underlying node command to handle.

I also can't reproduce with the latest Node:

$ tsx --env-file=.env ./test.ts
right
$ node -v
v22.9.0

But you're likely encountering https://github.com/nodejs/node/issues/52084