privatenumber / tsx

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

watch mode breaks stdout / piping #184

Open Nicholaiii opened 1 year ago

Nicholaiii commented 1 year ago

Bug description

When using watch mode, piping stdout is broken, it doesn't do anything at all, just prints straight to console. It works without watch.

Reproduction

I can't do this without dependencies, ultimately my example is piping into one.

Environment

System:
    OS: Windows 10 10.0.22621
    CPU: (12) x64 AMD Ryzen 5 5500U with Radeon Graphics
    Memory: 1.12 GB / 15.37 GB
  Binaries:
    Node: 18.8.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.2.0 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    tsx: ^3.12.2 => 3.12.2

Can you work on a fix?

privatenumber commented 1 year ago

I can't do this without dependencies, ultimately my example is piping into one.

That's fine if you can strip it down to bare minimums. Please provide a link to a minimal reproduction repository.

Nicholaiii commented 1 year ago

https://github.com/Nicholaiii/tsx-pipe

I am now only getting this issue on the first log line. I have no idea what (if anything) changed. npm run normal (works immediately) npm run watch (works after first log)

piotrek-szczygiel commented 1 year ago

Same thing is happening when using concurrently to run tsx watch, no console output at all.

privatenumber commented 1 year ago

@piotrek-szczygiel

Thanks for your comment! But, with the limited info provided, I'm not sure if it's relevant to this thread, so I'm gonna hide it for now.

If you can share more details and steps to reproduce in a new Issue, that would be super helpful. Thanks, and let me know if you need any help.

torbjornvatn commented 1 year ago

@privatenumber I have the same problem too

I run npx tsx watch src/intex.ts | jg but the output from the program isn't parsable by jq and I get parse error: Invalid numeric literal at line 1, column 3

If I run npx tsx src/intex.ts | jg it works just fine.

src/index.ts can be as simple as:

console.log(`{"message": "Hello World!"}`)
privatenumber commented 1 year ago

Gotcha, thanks for the repro. Happy to accept a PR.

hornta commented 8 months ago

Same thing is happening when using concurrently to run tsx watch, no console output at all.

Same thing for me, this is the only reason I cant switch from ts-node.