Repository navigation
ts-node dos not recognize end of input; keeps printing "..." #2150
Description
Activity
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-logoi will spend some time on this as I am able and if fixed I'll submit a patch.
Same problem just started. Worth noting that it's something that starts happening on its own. Just this morning
ts-nodewas 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.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 ofnode_modules/@types/node/process.d.tsfile.It seemsts-nodetries to parseprocess.d.tsfile, which then goes south. But sure it wasn't always like this, right? So I tried downgradingtypescript = 4.3.2and@types/node = 18.11.9, but it changed nothing.WorkaroundSolutionEdit
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-nodethe 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.inputis 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 likenode_modules/ts-node/dist/ts-transpile-module.d.ts(and there are similar ones) that only contain exactly theexport {};line. But I stopped digging here.As mentioned in "Workaround" section, the exception only occurs on the first input, so, well, at least
ts-nodestarts working. I don't plan to do further digging as I spent more time than I planned. Leaving that to any other motivated person 😊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.
- added a commit that references this issue
on Apr 1, 2025
Search Terms
repl, newline, ...
Expected Behavior
Expression is evaluted in REPL after hitting "enter":
Actual Behavior
Nothing happens, ts-node behavies like it expects the input to continue:
If you input something that is not a valid expression, you get something else:
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
OSX 15.3.1: