Quantcast
Channel: Node.js Tools for Visual Studio
Viewing all articles
Browse latest Browse all 4630

Created Issue: Message stating that npm execution is complete appears in Output before last of npm output [580]

$
0
0
This is undoubtedly an artifact of reading output asynchronously, and I'm not sure how to fix it, but you sometimes see output like the following from npm:


====Executing command 'npm install '====

npm ERR! install Couldn't read dependencies
npm ERR! Failed to parse json
npm ERR! Unexpected token /
npm ERR! File: C:\GitWork\testing\NodejsConsoleApp10\NodejsConsoleApp10\package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"

====npm command completed with exit code 1====

npm ERR! cwd C:\GitWork\testing\NodejsConsoleApp10\NodejsConsoleApp10


Note that the last line of output appears after the notification that npm completed. This occurs because npm's output and error streams are read asynchronously, meaning it's possible for the last reads and writes to occur after the process has exited.

In the status bar I get around this by simply ignoring any error/output writes that occur after the process has finished running, but if I do that in the Output window then some output would be missing, which I don't think is really acceptable.

I could fix this by using separate threads to read error and output streams synchronously, and fire events as if they were asynchronous. I'd then know when the end of both streams had been read and could delay firing the completion event until afterwards. This feels a bit heavy though. If there's a nice way of doing this with the asynchronous reads I'd vastly prefer to do that.

Note that the reason for the executing and completion notifications is to delimit the output from successive npm runs in the Output window, otherwise there would just be a long stream of npm's logged output and it would be impossible to see which output corresponded to which npm command. That being said, in theory we could just print a message showing what npm command is being executed before the command is started, and then just dispense with the completion message entirely.


Viewing all articles
Browse latest Browse all 4630

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>