audit-ci: Error: Invalid JSON (Unexpected " " at position 4 in state STOP)

Due to: https://github.com/IBM/audit-ci/issues/96

Yarn audit report results:
events.js:167
      throw er; // Unhandled 'error' event
      ^
Error: Invalid JSON (Unexpected " " at position 4 in state STOP)

(It’s visible here: https://travis-ci.org/sumup/circuit-ui/jobs/559411807)

Related: #102

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 3
  • Comments: 27 (10 by maintainers)

Commits related to this issue

Most upvoted comments

We were running into the same problem as described in the first post of this issue. After some debugging, I found out that the string in the buffer where the JSON decoding fails is <--- Last few GCs --->. Kinda strange, I was not expecting this string. Anyway, I’ve upped our --max_old_space_size and can now run audit-ci without issues.

The side effect of this change is that this process now has a significant memory footprint.

same issue here if I use version 2.5.1.

Yarn audit report results:
events.js:167
      throw er; // Unhandled 'error' event
      ^
Error: Invalid JSON (Unexpected " " at position 4 in state STOP)

if I revert to 2.1.0, another error 😂 image

@quinnturner I see the same problem with --json:

$ ./node_modules/.bin/audit-ci --json
Yarn audit report results:
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: Invalid JSON (Unexpected " " at position 4 in state STOP)

I tried looking into it a bit, but didn’t get too far. I only see why the error is thrown here: https://github.com/creationix/jsonparse/blob/master/jsonparse.js#L266

The problem is, that this.string is <--- and of course, this is not a number.

            if (isNaN(result)){
              console.error("result: "+result);
              console.error("this.string: "+this.string);
              console.error("n: "+n);
              return this.charError(buffer, i);
            }
result: NaN
this.string: <---
n: 32

And I also found out, that --report-type full did print the auditAdvisorys JSON. But then I didn’t find where the error really happened after that. This then for example was never called: https://github.com/IBM/audit-ci/blob/master/lib/yarn-auditer.js#L159-L169

We’re still running into this with the latest version 2.3.0:

❯ yarn list --depth 0 --pattern audit-ci
yarn list v1.13.0
└─ audit-ci@2.3.0
✨  Done in 0.51s.
yarn run v1.13.0
$ node ./node_modules/.bin/audit-ci --config .audit-ci.json --pass-enoaudit
Yarn audit report summary:
events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: Invalid JSON (Unexpected " " at position 4 in state STOP)

Any clues what’s going on?

we encountered this problem, turns out the CI environment we’re running in (travis) was using npm 5.6.0 which didn’t support audit yet and was causing misleading JSON error. Forcing the correct npm version resolved the problem for us.