npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

error Unexpected token in JSON at position

I have that problem too, also on AWS Ireland.

npm ERR! Unexpected token  in JSON at position 2079 while parsing near '...d-my-way-0.2.4.tgz"}...'

Using Ubuntu and just doing npm install of a project. Interestingly the position is almost the same. Maybe some networking problem with packet-sizes?


yes to the support@npmjs.com

I already forwarded this thread and how to reproduce it

#connect to ireland region
#if needed use node image
docker run --entrypoint=bash -it node:8.10
#just run npm install
npm install time-grunt@^1.4.0 --verbose

Let see how it goes


However as per npm documentation there is a public mirror at https://skimdb.npmjs.com/registry. Can we use this instead of https://registry.npmjs.org/ until this issue is resolved in AWS Ireland region?. Any suggestions.

Thanks
Kishore


What I Wanted to Do

npm install time-grunt@^1.4.0 --verbose

What Happened Instead

npm install time-grunt@^1.4.0 --verbose
npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'install',
npm verb cli   'time-grunt@^1.4.0',
npm verb cli   '--verbose' ]
npm info using npm@5.6.0
npm info using node@v8.10.0
npm verb npm-session 114c17b0d75ada0a
npm http fetch GET 200 https://registry.npmjs.org/time-grunt 137ms
npm verb stack SyntaxError: Unexpected token  in JSON at position 2078 while parsing near '...on":"0.2.3","depende...'
npm verb stack     at JSON.parse (<anonymous>)
npm verb stack     at parseJson (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/node_modules/json-parse-better-errors/index.js:7:17)
npm verb stack     at consumeBody.call.then.buffer (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/src/body.js:96:50)
npm verb stack     at <anonymous>
npm verb stack     at process._tickCallback (internal/process/next_tick.js:188:7)
npm verb cwd /tmp/build/7c4e1319
npm verb Linux 4.9.0-8-amd64
npm verb argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "time-grunt@^1.4.0" "--verbose"
npm verb node v8.10.0
npm verb npm  v5.6.0
npm ERR! Unexpected token  in JSON at position 2078 while parsing near '...on":"0.2.3","depende...'
npm verb exit [ 1, true ]

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-02-25T14_56_45_007Z-debug.log
root@ef275fef-0505-4949-5a05-f3450234b641:/tmp/build/7c4e1319# cat /root/.npm/_logs/2019-02-25T14_56_45_007Z-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   'install',
1 verbose cli   'time-grunt@^1.4.0',
1 verbose cli   '--verbose' ]
2 info using npm@5.6.0
3 info using node@v8.10.0
4 verbose npm-session 114c17b0d75ada0a
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 http fetch GET 200 https://registry.npmjs.org/time-grunt 137ms
8 silly fetchPackageMetaData error for time-grunt@^1.4.0 Unexpected token  in JSON at position 2078 while parsing near '...on":"0.2.3","depende...'
9 verbose stack SyntaxError: Unexpected token  in JSON at position 2078 while parsing near '...on":"0.2.3","depende...'
9 verbose stack     at JSON.parse (<anonymous>)
9 verbose stack     at parseJson (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/node_modules/json-parse-better-errors/index.js:7:17)
9 verbose stack     at consumeBody.call.then.buffer (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/src/body.js:96:50)
9 verbose stack     at <anonymous>
9 verbose stack     at process._tickCallback (internal/process/next_tick.js:188:7)
10 verbose cwd /tmp/build/7c4e1319
11 verbose Linux 4.9.0-8-amd64
12 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "time-grunt@^1.4.0" "--verbose"
13 verbose node v8.10.0
14 verbose npm  v5.6.0
15 error Unexpected token  in JSON at position 2078 while parsing near '...on":"0.2.3","depende...'
16 verbose exit [ 1, true ]

Reproduction Steps

docker run --entrypoint=bash -it node:8.10
npm install time-grunt@^1.4.0 --verbose

Details

We are working on aws ec2 instances. We tried several instance on Paris region it works, but on Ireland region it fail each time. So it might be linked to cloudflare or something linked to the geolocalisation.

It is currently the only package failing. Maybe other can be impacted but I dont know yet.

Platform Info

Debian stretch

$ npm --versions
{ npm: '5.6.0',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.7.0',
  icu: '60.1',
  modules: '57',
  nghttp2: '1.25.0',
  node: '8.10.0',
  openssl: '1.0.2n',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.1',
  v8: '6.2.414.50',
  zlib: '1.2.11' }

$ node -p process.platform
linux


Someone mentioned in that thread that the issue is fixed locally for them. Does it work after clearing the cache?


The same issue for is-string. Region - Ireland. And it works in Virginia

npm ERR! Unexpected token · in JSON at position 2023
npm ERR! {"_id":“is-string”,"_rev":“8-a4a63ff60d8dba9a7e00bb773a5f6969”,“name”:“is-string”,“description”:“Is this value a JS String object or primitive? This module works cross-realm/iframe, and despite ES6 @@toStringTag.”,“dist-tags”:{“latest”:“1.0.4”},“versions”:{“1.0.0”:{“name”:“is-string”,“version”:“1.0.0”,“author”:{“name”:“Jordan Harband”},“description”:“Is this value a JS String object or primitive? This module works cross-realm/iframe, and despite ES6 @@toStringTag.”,“license”:“MIT”,“main”:“index.js”,“scripts”:{“test”:“npm run lint && node --harmony --es-staging test.js && npm run security”,“coverage”:“covert test.js”,“coverage-quiet”:“covert test.js --quiet”,“lint”:“npm run jscs && npm run eslint”,“jscs”:“jscs test.js *.js”,“eslint”:“eslint test.js *.js”,“eccheck”:“editorconfig-tools check .js **/.js > /dev/null”,“security”:“nsp package”},“repository”:{“type”:“git”,“url”:“git://github.com/ljharb/is-string.git”},“keywords”:[“String”,“string”,“ES6”,“toStringTag”,"@@toStringTag",“String object”],“dependencies”:{},“devDependencies”:{“foreach”:"~2.0.5",“is”:"~2.2.0",“tape”:"~3.4.0",“indexof”:"~0.0.1",“covert”:“1.0.0”,“jscs”:"~1.10.0",“editorconfig-tools”:"~0.0.1",“nsp”:"~1.0.0",“eslint”:"~0.13.0",“semver”:"~4.2.0"},“testling”:{“files”:“test.js”,“browsers”:[“iexplore/6.0…latest”,“firefox/3.0…6.0”,“firefox/15.0…latest”,“firefox/nightly”,“chrome/4.0…10.0”,“chrome/20.0…latest”,“chrome/canary”,“opera/10.0…latest”,“opera/next”,“safari/4.0…latest”,“ipad/6.0…latest”,“iphone/6.0…latest”,“android-browser/4.2”]},“engines”:{“node”:">= 0.4"},“gitHead”:“b85f8e81b1b00643d732a91a28df2556b9019c0f”,“bugs”:{“url”:"https://github.com/ljharb/is-string/issues"},“homepage”:“https://github.com/ljharb/is-string”,"_id":“is-string@1.0.0”,"_shasum":“7f13aa94f67b7ed5c6c6884efd40192bf8b4a6c1”,"_from":".","_npmVersion":“2.3.0”,"_nodeVersion":“1.0.4”,"_npmUser":{“name”:“ljharb”,“email”:“ljharb@gmail.com”},“maintainers”:[{“name”:“ljharb”,“email”:“ljharb@gmail.com”}],“dist”:{“shasum”:"7f13aa94f67b7ed5c6c6884efd40192b···········································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································


The mirror doesn’t have scoped packages I think. Anyway, there’s a status message now.


We got the same issue with on AWS Ireland region
https://registry.npmjs.org/astw

The JSON response is broken with some weird chars

root@48babad8c93c:/# curl https://registry.npmjs.org/astw
    {"_id":"astw","_rev":"16-e78d3243d8d88f55165ba5d09af7606c","name":"astw","description":"walk the ast with references to parent nodes","dist-tags":{"latest":"2.2.0"},"versions":{"0.0.0":{"name":"astw","version":"0.0.0","description":"walk the ast with references to parent nodes","main":"index.js","dependencies":{"esprima":"1.0.2"},"devDependencies":{"tape":"~0.2.2","tap":"~0.4.0","escodegen":"~0.0.17"},"scripts":{"test":"tap test/*.js"},"testling":{"files":"test/*.js","browsers":["ie/6..latest","chrome/20..latest","firefox/10..latest","safari/latest","opera/11.0..latest","iphone/6","ipad/6"]},"repository":{"type":"git","url":"git://github.com/substack/astw.git"},"homepage":"https://github.com/substack/astw","keywords":["ast","walk","source","esprima"],"author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"},"license":"MIT","_id":"astw@0.0.0","dist":{"shasum":"4490866a3ef116aaf91adba63ca7ddf70b6d59bd","tarball":"https://registry.npmjs.org/astw/-/astw-0.0.0.tgz"},"_from":".","_npmVersion":"1.2.2","_npmUser":{"name":"substack","email":"mail@substack.net"},"maintainers":[{"name":"substack","email":"mail@substack.net"}],"directories":{}},"0.1.0":{"name":"astw","version":"0.1.0","description":"walk the ast with references to parent nodes","main":"index.js","dependencies":{"esprima-six":"0.0.3"},"devDependencies":{"tape":"~2.4.1","escodegen":"~0.0.17"},"scripts":{"test":"tape test/*.js"},"testling":{"files":"test/*.js","browsers":["ie/6..latest","chrome/20..latest","firefox/10..latest","safari/latest","opera/11.0..latest","iphone/6","ipad/6"]},"repository":{"type":"git","url":"git://github.com/substack/astw.git"},"homepage":"https://github.com/substack/astw"root@48babad8c93c:/#


Nope, As you can see in my reproduction steps we use clean docker image. We tried cache clean --force and other stuff but no improvement. It only impact all our instances in aws Irleland regions


This is also happening https://github.com/fastify/fastify/issues/1482. It’s quite disruptive.


Thank you @larsgw. I will follow the incident status.


This also seems to be affecting some users of is-string: https://github.com/ljharb/is-string/issues/8


answer from the support:

Thanks for contacting us. Sorry to hear you're encountering that issue.

Our CDN did report an issue with subscriptions yesterday. To learn more about that, please see this status update:

https://www.cloudflarestatus.com/incidents/ttlnz1424k8c

I wanted to check in to see if you're still experiencing an error. If so, please send over a full debug.log (located in your .npm directory) and also please go to this URL and let us know the output of the "colo" field. With that info, we'll know if it's related to our CDN data centers or not.

But is still not fixed for me. I will let you know If I get more answer


This is still happening for us.


I have this issue on a clean CI environment, there is no caching there.


I think this issue is clearly a badly behaving edge node in Ireland :tired_face: I’ve just had a very similar issue [registry] Getting a truncated JSON response from the registry while installing and in my steps to reproduce I show that the problem goes away if you tunnel-bear out of Ireland.

I don’t know what the infrastructure looks like but if we can identify the edge node and take it out of commission for the time being that would save a lot of people some heart ache :confounded:


https://github.com/yarnpkg/yarn/issues/7067#issuecomment-467917635

for temporary resolution for fastify


Sorry, forgot about that. :sweat_smile:


@talset when you say “answer from support” you mean npm support yes?

Have you pointed them to this thread? I have given quite specific instructions to recreate the issue over on my report (linked above) so they should be able to recreate the issue :+1: