简体   繁体   中英

Weird behavior in Node REPL when pasting text (Windows OS) - Crashes

I'm sorry if this has already been posted but I have no idea how to search for what I am experiencing. This be might Windows OS specific I don't know.

I use VS code as my IDE and when testing node code I open the integrated terminal and run node from there. I then copy and paste a lot of my code to run them line by line and do testing etc. I noticed that it would completely lock up node when pasting sometimes. After a painstakingly long time I finally found it only happens when I copied and pasted large amounts of text. IE I could highlight my whole code, copy and paste and it would lock up node. But then if I tried copying only half and executed it then the second half and executed it, it would work.

I thought this was VS code related until recently I did it directly in the node REPL outside of VS code and it crashed there also.

Has anyone else experienced this? I did a google and found some reported bugs ages ago similar to what I'm experiencing but they were meant to be fixed.

To make this even weirder, sometimes I CAN execute the large amount of text under certain conditions. It seems to work if I copy and paste in small batches first, ie split the code into 3 parts and execute them individually, then if I now go back and highlight it all and copy and paste, it executes it fine. But then I load a new node up, copy and paste all code again and it fails. Not really sure what's going on.

EDIT: Here is the code below. If you open the node REPL and paste of this, it will freeze on the first line (so don't worry about the requires not being able to find the modules). NOTE; the code has been changed to take out the IP so IF does execute it will error as I just replaced some keywords with random text. Ignore this, the point of it is to show that it won't copy and paste past the first line, it will freeze. Any help appreciated!

//{"_id":"56aba3108d6d183da42403c2"}
//placeholder
const request = require('request');
var mongoose = require ("mongoose");
var lodash = require ("lodash");
var myFuncs = require("./functions");



var item_urls;
var options = {
    json: true
  };

var test = [] ;
function updateDB (){
    var url = "get stuff";


    request(url, options, (error, res, body) =>{
        if (error) {
            return console.log(error)
          };

          if (!error && res.statusCode == 200) {
            console.log("executing cb1");
            item_urls = body.payload.items;
            myFuncs.fixItemIDs (item_urls);
            var primes = item_urls.filter(item => item.item_name.includes("Strun Wraith Set")); 
            for (item in primes) 
            {
                let url = `https://get more stuff/v1/items/${primes[item].url_name}`;
               // console.log (url);
                request(url, options, (error, res, body) =>{
                    if (error) {
                        return console.log(error)
                      };

                      if (!error && res.statusCode == 200) {

                          console.log(`Getting item ${url}`);
                          test.push(body.payload.item);
                          myFuncs.fixItemIDs (test);
                      }
                    });

            };  
            console.log ("done");          


          };
    });
}

updateDB();

I logged it as a Bug on Github and someone else tested and reproduced the issue. It is now a confirmed bug they are going to look into. It is even present in beta/latest version.

https://github.com/nodejs/node/issues/32999

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM