Running the same javascript script in node and ts-node should allow the script to access the TTY.
This is not the case. Here is an example script:
console.log(`process.stdin.isTTY = ${process.stdin.isTTY}`);
process.stdin.setRawMode(true);
Using node, process.stdin.isTTY = true but with ts-node, process.stdin.isTTY = undefined.
Also, calling process.stdin.setRawMode(true); with ts-node throws an exception, but not with node.
Have you tried both with and without the REPL? What is the exception?
On Tue, Jul 21, 2020, 3:09 AM Daniel-Khodabakhsh notifications@github.com
wrote:
Running the same javascript script in node and ts-node should allow the
script to access the TTY.
This is not the case. Here is an example script:console.log(
process.stdin.isTTY = ${process.stdin.isTTY});
process.stdin.setRawMode(true);Using node, process.stdin.isTTY = true but with ts-node, process.stdin.isTTY
= undefined.
Also, calling process.stdin.setRawMode(true); with ts-node throws an
exception, but not with node.
Specifications
- ts-node version: v8.10.2
- node version:v12.18.2
- TypeScript version: v3.9.7
- tsconfig.json: None
- Operating system and version: Windows 10
- If Windows, are you using WSL or WSL2?: No
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/TypeStrong/ts-node/issues/1081, or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAC35OEDH52RS5PFCV2CZJ3R4U5JFANCNFSM4PDHUAZA
.
I've tried both ts-node -i myscript.ts and ts-node myscript.ts but still get the same error.
Here's the error message I get:
process.stdin.setRawMode(true);
^
TypeError: process.stdin.setRawMode is not a function
I tried other TTY environments (cmd and ps1) and this issue only occurs for my main environment: MSYS2(mintty+bash).
node is working fine with MSYS2(mintty+bash) though.
This certainly makes it sound like a problem with MSYS2 or your node installation, not ts-node. Some things you can do to collect diagnostic information:
which ts-node
ts-node -p -e process.platform
node -p -e process.platform
# install ts-node locally, then do:
node --require ts-node/register ./your-reproduction-script.ts
Here's the output you requested:
$ which ts-node
node -p -e process.platform/c/Program Files/nodejs/ts-node
$ ts-node -p -e process.platform
[eval].ts(1,1): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i @types/node`.
$ node -p -e process.platform
win32
That second line may raise suspicions but I have the following line within my ts script which plays well with linters and running the script:
/// <reference types="C:\Program Files\nodejs\node_modules\@types\node\" />
I have ts-node installed globally but this worked:
$ node --require="/c/Program Files/nodejs/node_modules/ts-node/register" myscript.ts
<all tty related functionality works!>
Thanks for that!
I looked at the gist but my environment doesn't have this issue, at least not with node:
$ node -p -e "process.stdout.isTTY"
true
node can run the script just fine in MSYS2, wouldn't this indicate the issue is with ts-node and not the environment?
The node -r ts-node/register ... solves it for me but it would be neat if ts-node command would work out-of-the-box for all tty environments (or at least the ones supported by node).
The issue might be caused by the shims used to invoke any binaries installed via npm, not just ts-node. npm spits out a script. When you run tsc, grunt, ts-node, etc, you are running this shim script.
I'm not sure how MSYS2 works, so I'm not sure what it's running when you type ts-node. But that's my next suggestion: narrow down precisely which script is being invoked by msys2 when you run ts-node. Then try making a copy and modifying it so that it doesn't run ts-node, but instead runs something else that lets you test process.stdout.isTTY.
@Daniel-Khodabakhsh any luck debugging this?
Hey sorry @cspotcode. Thanks for the added information on debugging it but I've had to switch gears.
I'm ok with closing the ticket, where the solution is to run scripts via node -r ..., or keeping it open and I can revisit and debug further at a later date.
What should I do with this ticket?
No problem, we can leave it open, and I'll mark it as "needs more info" and rename the title to mention MSYS2 specifically, since my testing shows that it works correctly on Windows outside of MSYS2.