Node v8.11.2
Win10 Pro
I run node from cmd.exe, and simply paste this code using r-click:
var crypto = require('crypto');
function hmacN(N)
{
console.log(N);
}
The moment I paste it, node exists and I get this output:
Microsoft Windows [Version 10.0.17134.81]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\username>node
> var crypto = require('crypto');
undefined
> function hmacN(N)
... {
... console.log(N);
... }
undefined
>
C:\Users\username>
This used to work properly (e.g. it shouldn't exit), that's how I always test snippets by pasting them into node-repl console.
Interesting observation: if I paste incomplete code (without last }) then it won't exit and I need to manually complete it with the last brace and can continue. Or, if pasted block doesn't end with a new line character, then it will also won't exist and will wait for manual [ENTER] key press. Also, to confirm, the problem happens on 8.11.3 as well
I cannot reproduce this. Are you using any console emulator like ConEmu?
No, I use regular cmd.exe, plain vanilla win10 pro.
I tried to do the same on my home PC and I don't have that problem. What could possibly make it fail on my other PC?
@pps83 could you please
This will allow to check the case when app you are copying from adds some additional characters (like Enter,Ctrl+d that will result in this behavior).
Also could you also check if it affects latest node? (10.7.0 at a time of writing).
I use awesome notepad++, so it's plain text.
current 10.0.7 has identical problem for me. I have a guess of what might be happening. Could it be that pasted text ends up with unix-style line endings ('\n' instead of '\r\n')? I'm connected from a mac and I RDP to Windows box where I work. I also tried to connect using teamviewer and I had identical problem. Perhaps, when text Ctrl+C'opied it gets converted to mac-style line endings in the buffer? That's the only guess I have.
However, I also RDP to this windows from another windows PC (with no Mac involved at all) and I end up with the same problem.
I have exactly the same problem. Independently from where I have copied a text from notepad++ or from this thread getting your piece of code literally the nodejs throws me out of REPL into w10 command prompt.
@pps83 There is not a solution but temporal remedy:
I used .editor command then pasted a snippet and typed ^D. The output is as follows:
(first goes an attempt without .editor then with it)
I:\nodejs>node
> var crypto = require('crypto');
undefined
> function hmacN(N)
... {
... console.log(N);
... }
undefined
>
I:\nodejs>node
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
var crypto = require('crypto');
function hmacN(N)
{
console.log(N);
}
undefined
> hmacN(10)
10
undefined
>
This works for me. Try it on your PC.
Another option:
I'm having this issue too.
Both in PowerShell and CMD.
It seems to only happen when more than one line break is in the pasted text. For example, pasting the following code will not cause the REPL to exit.
console.log('line 1') // <- there is a line break here
And here's the output.
C:\Users\Jordan>node
> console.log('line 1')
line 1
undefined
> _
However, this code will cause the REPL to exit.
console.log('line 1')
console.log('line 2') // <- there is a line break here
And here's the output.
C:\Users\Jordan>node
> console.log('line 1')
line 1
undefined
> console.log('line 2') // <- there is a line break here
line 2
undefined
>
C:\Users\Jordan>_
@vuGitH's .editor workaround does prevent the REPL from exiting when pressing CTRL+D after pasting the code. Here's that output.
C:\Users\Jordan>node
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
console.log('line 1')
console.log('line 2') // <- there is a line break here
line 1
line 2
undefined
> _
I just tried this on another computer running Windows 10.0.16299.547 and Node.js v8.11.4 and it did _not_ exhibit this problem.
Then I tried it on another computer running Windows 10.0.17134.228 and Node.js v8.11.3 and it _did_ exhibit the problem. So maybe something changed in Windows that's contributing to this bug.
@jordanbtucker Jordan! Thank you for feedback!
It also reproduces on my box
Can be reproduced by:
require('repl').start({
breakEvalOnSigint: true
});
Switching breakEvalOnSigint to false makes the problem go away.
/cc @nodejs/platform-windows @nodejs/repl
I assume the key question here is why the process exits, right? Has anybody been able to figure out whether that is because of an emtpy event loop or because of an explicit exit() call somewhere?
@addaleax Yes, the loop is empty (uv_loop_alive returns false), but I am not sure why.
Can anyone reproduce this on Windows 7?
Does not reproduce on win7 on my VM.
Setting the console back into raw mode (https://github.com/nodejs/node/blob/master/lib/repl.js#L338) triggers this.
This can also be triggered by:
process.stdin.on('data', () => {
process.stdin.setRawMode(true);
process.stdin.setRawMode(false);
});
and writing something to stdin.
Yes, the loop is empty (uv_loop_alive returns false), but I am not sure why.
Because the call to uv_tty_read_stop failed when calling uv_tty_set_mode with UV_TTY_MODE_NORMAL, consequently uv_tty_read_start wasn't called. setRawMode returned an error code, but it's ignored on JS side.
uv_tty_read_stop failed because the call to WriteConsoleInputW failed with ERROR_INVALID_PARAMETER. Perhaps Windows 10 no longer supports writing bullshit events.
Things to do:
setRawMode on Node.js side.PR with libuv fix: https://github.com/libuv/libuv/pull/1989
Reopening until the next libuv update.
Most helpful comment
This can also be triggered by:
and writing something to
stdin.