[registry] Getting a truncated JSON response from the registry while installing

What I Wanted to Do

I was trying to install a project that is known to be working on other people’s machines and it failed. I have subsequently tracked down the issue to a single package.

What Happened Instead

I got a somewhat confusing error after running npm install

npm ERR! Unexpected token  in JSON at position 1747 while parsing near '...ber-cli-dependency-c...'

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mansona/.npm/_logs/2019-02-27T07_32_48_400Z-debug.log

Reproduction Steps

So I’m almost 100% convinced that this is a bad package stuck on an edge node on your CDN because I just tried this while tunnelling (using tunnelbear) to Canada and the problem went away. I then verified that the problem still happened while tunnelling to Ireland (where I’m actually located) and the problem came back, so It’s not a network specific issue.

Steps to reproduce:

  • Use a VPN to tunnel to Ireland. I’m using tunnelbear but I don’t know if that is relevant
  • clean your cache using npm cache clean --force
  • initialise a npm project using npm init
    • I don’t know if this is strictly necessary but I did this because I wanted to verify if it would create a package-lock.json
  • install ember-cli-dependency-checker e.g. npm i ember-cli-dependency-checker

This will then give the following error:

npm ERR! Unexpected token  in JSON at position 1747 while parsing near '...ber-cli-dependency-c...'

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mansona/.npm/_logs/2019-02-27T07_37_01_146Z-debug.log

and here is the full debug log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'i',
1 verbose cli   'ember-cli-dependency-checker' ]
2 info using npm@6.7.0
3 info using node@v10.12.0
4 verbose npm-session 71a5f9dbf0ac9a5b
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 http fetch GET 200 https://registry.npmjs.org/ember-cli-dependency-checker 24ms (from cache)
8 silly fetchPackageMetaData error for ember-cli-dependency-checker@latest Unexpected token  in JSON at position 1747 while parsing near '...ber-cli-dependency-c...'
9 timing stage:rollbackFailedOptional Completed in 0ms
10 timing stage:runTopLevelLifecycles Completed in 80ms
11 verbose stack SyntaxError: Unexpected token  in JSON at position 1747 while parsing near '...ber-cli-dependency-c...'
11 verbose stack     at JSON.parse (<anonymous>)
11 verbose stack     at parseJson (/usr/local/lib/node_modules/npm/node_modules/json-parse-better-errors/index.js:7:17)
11 verbose stack     at consumeBody.call.then.buffer (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/body.js:96:50)
11 verbose stack     at process._tickCallback (internal/process/next_tick.js:68:7)
12 verbose cwd /Users/mansona/temp/wut
13 verbose Darwin 18.2.0
14 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "i" "ember-cli-dependency-checker"
15 verbose node v10.12.0
16 verbose npm  v6.7.0
17 error Unexpected token  in JSON at position 1747 while parsing near '...ber-cli-dependency-c...'
18 verbose exit [ 1, true ]

I also went into the json-parse-better-errors package and added a quick console log to find out what the full text it is trying to parse and here is what is getting passed into JSON.parse:

{"versions":{"0.0.1":{"name":"ember-cli-dependency-checker","version":"0.0.1","directories":{},"dist":{"shasum":"937af1a6ad8fd7fa6d796b0267943ce87aef723a","tarball":"https://registry.npmjs.org/ember-cli-dependency-checker/-/ember-cli-dependency-checker-0.0.1.tgz"}},"0.0.2":{"name":"ember-cli-dependency-checker","version":"0.0.2","devDependencies":{"body-parser":"^1.2.0","broccoli-asset-rev":"0.3.1","broccoli-ember-hbs-template-compiler":"^1.6.1","ember-cli":"0.1.2","ember-cli-content-security-policy":"0.3.0","ember-export-application-global":"^1.0.0","ember-cli-ic-ajax":"0.1.1","ember-cli-inject-live-reload":"^1.3.0","ember-cli-qunit":"0.1.0","ember-data":"1.0.0-beta.10","express":"^4.8.5","glob":"^4.0.5"},"directories":{"doc":"doc","test":"tests"},"dist":{"shasum":"1b321a54b40ae1e50ceb9737ca4188a69c55800f","tarball":"https://registry.npmjs.org/ember-cli-dependency-checker/-/ember-cli-dependency-checker-0.0.2.tgz"},"engines":{"node":">= 0.10.0"}},"0.0.3":{"name":"ember-cli-dependency-checker","version":"0.0.3","dependencies":{"chalk":"^0.5.1","semver":"^4.1.0"},"devDependencies":{"body-parser":"^1.2.0","broccoli-asset-rev":"0.3.1","broccoli-ember-hbs-template-compiler":"^1.6.1","ember-cli":"0.1.2","ember-cli-content-security-policy":"0.3.0","ember-export-application-global":"^1.0.0","ember-cli-ic-ajax":"0.1.1","ember-cli-inject-live-reload":"^1.3.0","ember-cli-qunit":"0.1.0","ember-data":"1.0.0-beta.10","express":"^4.8.5","glob":"^4.0.5"},"directories":{"doc":"doc","test":"tests"},"dist":{"shasum":"2f5bdd2e50a35a62c3d830138f1023071344e7a0","tarball":"https://registry.npmjs.org/ember-cli-dependency-checker/-/ember-cli-dependency-checker-0.0.3.tgz"},"engines":{"node":">= 0.10.0"}},"0.0.4":{"name":"ember-cli-dependency-c

and as you can see it’s quite abruptly truncated :see_no_evil:

Details

I have given most of the details in the above section. I will say that I also tested this in yarn (after running yarn cache clean) and the problem is still there which is what makes me think this is more of a registry issue.

I also tried this with the latest npm version v6.8.0 and latest -1 v6.7.0 and it still has the same issue.

Platform Info

$ npm --versions
{ wut: '1.0.0',
  npm: '6.8.0',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.12.0',
  openssl: '1.1.0i',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.35',
  zlib: '1.2.11' }
$ node -p process.platform
darwin

Slightly earlier report, also featuring Ireland: error Unexpected token in JSON at position

1 Like

Yea thanks! I also commented over there too :+1:

I did try to do a search for an existing issue before hand but I must have missed it :see_no_evil: it did pop up in the “Suggested Topics” after I had posted it though.

I’m not going to close this as a duplicate for now because it lays out steps to reproduce that someone in the npm offices might be able to follow :thinking: which might be useful

1 Like

You can subscribe to updates here.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.