Skip to content

ts-node dos not recognize end of input; keeps printing "..." #2150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ralekseev-insify opened this issue Feb 11, 2025 · 5 comments · May be fixed by #2156
Open

ts-node dos not recognize end of input; keeps printing "..." #2150

ralekseev-insify opened this issue Feb 11, 2025 · 5 comments · May be fixed by #2156

Comments

@ralekseev-insify
Copy link

Search Terms

repl, newline, ...

Expected Behavior

Expression is evaluted in REPL after hitting "enter":

> 1
1
>

Actual Behavior

Nothing happens, ts-node behavies like it expects the input to continue:

> 1
... 
... 
... 

If you input something that is not a valid expression, you get something else:

> a
<repl>.ts:4:1 - error TS2304: Cannot find name 'a'.

4 a
  ~
<repl>.ts:3:1694 - error TS1005: '=' expected.

3 declare import assert = require('assert');declare import async_hooks = require('async_hooks');declare import buffer = require('buffer');declare import child_process = require('child_process');declare import cluster = require('cluster');declare import constants = require('constants');declare import crypto = require('crypto');declare import dgram = require('dgram');declare import diagnostics_channel = require('diagnostics_channel');declare import dns = require('dns');declare import domain = require('domain');declare import events = require('events');declare import fs = require('fs');declare import http = require('http');declare import http2 = require('http2');declare import https = require('https');declare import inspector = require('inspector');declare import net = require('net');declare import os = require('os');declare import path = require('path');declare import perf_hooks = require('perf_hooks');declare import punycode = require('punycode');declare import querystring = require('querystring');declare import readline = require('readline');declare import repl = require('repl');declare import stream = require('stream');declare import string_decoder = require('string_decoder');declare import sys = require('sys');declare import timers = require('timers');declare import tls = require('tls');declare import trace_events = require('trace_events');declare import tty = require('tty');declare import url = require('url');declare import util = require('util');declare import v8 = require('v8');declare import vm = require('vm');declare import wasi = require('wasi');declare import worker_threads = require('worker_threads');declare import zlib = require('zlib');declare import node:sea = require('node:sea');declare import node:sqlite = require('node:sqlite');declare import node:test = require('node:test')

Steps to reproduce the problem

I don't know. This happens on my machine, I have not been able to find what triggers it.
I have cleaned absolutely everything node-related that I could find on my machine several times, including all the caches. It is still happening.

Minimal reproduction

Specifications

  • ts-node version:
  • node version:
  • TypeScript version:
  • tsconfig.json, if you're using one:
ts-node v10.9.2
node v23.7.0
compiler v5.7.3
  • package.json:
-
  • Operating system and version:
    OSX 15.3.1:
@cclamb
Copy link

cclamb commented Mar 29, 2025

Same problem here.

Specific information to recreate:
ts-node v10.9.2 /usr/lib/node_modules/ts-node
node v23.9.0
compiler v5.8.2 /usr/lib/node_modules/typescript/lib/typescript.js
(no tsconfig when this occurs)

OS/Version:

NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://gitlab.archlinux.org/groups/archlinux/-/issues"
PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"
LOGO=archlinux-logo

i will spend some time on this as I am able and if fixed I'll submit a patch.

@Hi-Angel
Copy link

Hi-Angel commented Mar 31, 2025

Same problem just started. Worth noting that it's something that starts happening on its own. Just this morning ts-node was working fine and now it indefinitely waits for more input, no matter what valid finished code you enter. The only way to make it stop waiting is to pass invalid code.

@Hi-Angel
Copy link

Hi-Angel commented Apr 1, 2025

Dug into for a while, I am at loss.

I found that this "sea" thing from the declare import node:sea = require('node:sea'); snippet is part of node_modules/@types/node/process.d.ts file.It seems ts-node tries to parse process.d.ts file, which then goes south. But sure it wasn't always like this, right? So I tried downgrading typescript = 4.3.2 and @types/node = 18.11.9, but it changed nothing.

@Hi-Angel
Copy link

Hi-Angel commented Apr 1, 2025

Workaround Solution

Edit node_modules/ts-node/dist/repl.js (e.g. on my Archlinux global installation it is /usr/lib/node_modules/ts-node/dist/repl.js), and change one line as follows (you basically just add a && !name.includes(':') && code):

@@ -0,0 +0,0 @@
                 state.input += `// @ts-ignore\n${module_1.builtinModules
                     .filter((name) => !name.startsWith('_') &&
-                    !name.includes('/') &&
+                    !name.includes('/') && !name.includes(':') &&
                     !['console', 'module', 'process'].includes(name))
                     .map((name) => `declare import ${name} = require('${name}')`)
                     .join(';')}\n`;

After you save it and run ts-node the first command will give your exception (Idk why), but further commands will work as expected.

Explanation:

Just as I wrote previous comment I found where code is being generated, this paragraph.

state.input is text that goes before a code a user enters.

I also found that problem seems to come down to colons being in the identifier name (as I suspected from the beginning and finally got to test it). If I replace whole algo with hardcoded string, the problem with indefinite wait disappears after I remove all colon-containing identifiers.

However, now any first input would give this exception:

/tmp/<repl>.ts:3
export {};
^^^^^^

Uncaught SyntaxError: Unexpected token 'export'

Not sure where it's coming from. Tried commenting out the state.input += 'export {};void 0; line, still get the error. I think it comes from the files like node_modules/ts-node/dist/ts-transpile-module.d.ts (and there are similar ones) that only contain exactly the export {}; line. But I stopped digging here.

As mentioned in "Workaround" section, the exception only occurs on the first input, so, well, at least ts-node starts working. I don't plan to do further digging as I spent more time than I planned. Leaving that to any other motivated person 😊

@Hi-Angel
Copy link

Hi-Angel commented Apr 1, 2025

However, now any first input would give this exception:

/tmp/.ts:3
export {};
^^^^^^

Uncaught SyntaxError: Unexpected token 'export'
Not sure where it's coming from.

Actually, nvm the exception, my "workaround" is the solution. I just found that the exception only appears with newer typescript, but with deps downgraded per my comment above the problem doesn't appear.

Hi-Angel added a commit to Hi-Angel/ts-node that referenced this issue Apr 1, 2025
These would otherwise result in syntax like `… node:sea = …`, which
causes further problems with indefinite wait.

Fixes: TypeStrong#2150
@Hi-Angel Hi-Angel linked a pull request Apr 1, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants