TypeStrong / ts-node

TypeScript execution and REPL for node.js
https://typestrong.org/ts-node
MIT License
12.75k stars 529 forks source link

calling `repl.start()` causes a doubling of stdin/stdout #2107

Open natemwilson opened 5 months ago

natemwilson commented 5 months ago

Search Terms

repl repl.start() context double STDIN STDOUT

Expected Behavior

STDOUT is not double printed

Actual Behavior

STDOUT is double printed

Steps to reproduce the problem

I want a ts-node repl, with all its benefits, with context from my app attached, (note I would in reality attach an imported module, but here am just attaching a variable to illustrate my need minimally.) Since I want context attached to my repl, I am using the node built-in package, repl, like so:

example.ts

import repl from "repl";

const foo = "bar";

const replServer = repl.start();

replServer.context.foo = foo;

Maybe this is not best practice, if so, please advise.

If I try to run the script example.ts with ts-node, then type the six characters, f,o,o,b,a,r, I see the following output:

$ npx ts-node  -r ./example.ts
> ffoobbaarr

So the bug is that every input is doubled, as I would expect to only see foobar.

Minimal reproduction

https://github.com/TypeStrong/ts-node-repros/pull/38

Specifications


* Operating system and version:
Mac OSX 13.4