Json parse failure messages are misleading under some circumstances.
hope-church-tritech opened this issue · 3 comments
When an error occurs parsing the json from npm audit
result while running better-npm-audit audit
, the error message is:
Failed parsing .nsprc file: SyntaxError: Unexpected end of JSON input
Unable to process the JSON buffer string.
regardless of whether there is a .nsprc file.
The offending line is:
better-npm-audit/src/utils/common.ts
Line 23 in 0b7259f
Hi @hope-church-tritech, thanks for reporting this. I think it could be the JSON output from the npm audit
result being invalid/incomplete.
May I know what would you see if you put a console.log('jsonBuffer', jsonBuffer);
in your /node_modules/better-npm-audit/index.js
around line 35, and run it again?
// Once the stdout has completed, process the output
if (audit.stderr) {
audit.stderr.on('close', function () {
console.log('jsonBuffer', jsonBuffer);
// Analyze the npm audit response
The particular issue I was having was that the stderr & stdout of npm audit
were both blank, causing the aforementioned output. This seems misleading since the .nsprc
file was not where the invalid json was originating from, which was the impetus for writing up this issue.
I've already found and fixed what was causing my specific problem, which is that an ENOENT error occurs when trying to call npm audit
on Ubuntu 20.04 when node is installed via snap instead of apt.
I was getting a similar issue because I misspelled .nsprc as .npmrc