NPM "Unexpected end of JSON input while parsing near" in build pipeline
Asked Answered
N

1

10

context

NPM version : 8.9.4
npm version : 6.9.0

We are using azure devops build pipelines with windows vs2017 hosted agents

problem

every ~ 1 in 10 builds Fails with the following error:

error

verbose stack SyntaxError: Unexpected end of JSON   input while parsing near '...st":{"integrity":"sha' 

18263 verbose stack     at JSON.parse (<anonymous>)  

18263 verbose stack     at parseJson (C:\npm\prefix\node_modules\npm\node_modules\json-parse-better-errors\index.js:7:17)  

18263 verbose stack     at consumeBody.call.then.buffer (C:\npm\prefix\node_modules\npm\node_modules\node-fetch-npm\src\body.js:96:50)
18263 verbose stack     at <anonymous>  

18263 verbose stack     at process._tickCallback (internal/process/next_tick.js:188:7)  

the JSON it cant parse varies.

Things I have already tried

  • use npm ci instead op npm install

  • have a build task that removes the npm chache before the npm install. (npm cache clean --force)

  • have a build task that changes the used registery. (config set registry "https://registry.npmjs.com/")

Nobukonoby answered 26/4, 2019 at 8:22 Comment(4)
We get the same thing but not quite as regular as you. When it does go it can take lots of rebuilds to get it to work again! :( Did you ever resolve this?Felicio
Did you ever resolve this? We get this a lot the last few weeksSly
Same here - getting this quite regularly every couple of builds. Some solutions suggest running "npm cache clean --force" but this doesn't solve/helpImbed
Just started randomly getting this yesterday. Today it's like 1 out of 5 builds pass. Looks like the problem child is with json-parse-better-errors package. The error message is always different but it's always complaining about trying to parse json in their readme file.Rebut
D
0

If 9 out of 10 builds are succeeding, perhaps the problem isn't in your npm cache, perhaps it's your build workspace. Have you tried adding this to your build pipeline at the start of your job steps?

jobs:
- job:
  workspace:
    clean: all
  # ... other job settings
  steps:
  # ... build steps
Decline answered 21/2, 2021 at 17:59 Comment(1)
That shouldn't matter really, because on a hosted agent the workspace is clean every time automatically.Grimy

© 2022 - 2024 — McMap. All rights reserved.