Skip to content

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

@natemwilson

Description

@natemwilson

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

TypeStrong/ts-node-repros#38

Specifications

  • ts-node version: v10.9.2
  • node version: v20.11.0
  • TypeScript version: v5.3.3
  • tsconfig.json, if you're using one:
{}
  • package.json:
{
  "dependencies": {
    "ts-node": "latest",
    "typescript": "latest"
  }
}

  • Operating system and version:
    Mac OSX 13.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions