I’m trying to load a 6 line js file into the Node REPL using the .load function:
function reverse(string) {
return string.split("").reverse().join("");
}
function palindrome(string) {
return string === reverse(string);
}
The result is an infinite loop printing the first line of the file (see image). I have to kill the terminal to make it stop loading this one line of code. Is this a bug in Node, or am I missing something?
I’m using Ubuntu 22.04.01 LTS and Node.js v18.13.0.
en@dangerous:~/Documents/tutorial/js_tutorial$ node
Welcome to Node.js v18.13.0.
Type ".help" for more information.
> .load palindrome.js
2
Answers
I am also going through the Learn Enough to be Dangerous courses and I ran into exactly the same problem.
As far as I can tell it has something to do with the node version since I was also in Node v18.13.0. I also tried 19.6.1 but the same thing happened.
I decided to go backward and attempted to use 14.20.0 and low and behold I was able to run the palindrome.js file in a repl with node. I haven’t tested versions in between 14.20.0 and 18.13.0, so im not sure which version this started happening with.
Update—
I did some trial and error and I found that the issue starts specifically with 18.13.0. 18.12.1 runs the palindrome.js file just fine.
For anyone curious this is what is in the palindrome.js file:
This is a bug that started in v18.13 and was discovered by someone using v19.6. A fix has been made in this PR: repl: fix .load infinite loop caused by shared use of lineEnding RegExp
#46742. The PR has been merged into the v19, but not yet into v18. I commented there to make a request that the fix be backported into v18, since at the time of this writing, v18 is in "Active LTS" status.