question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected end of JSON input

See original GitHub issue

First of all I love this utility, thanks for making!

I am getting the following error:

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at getDependencyTree (/Users/me/.config/yarn/global/node_modules/cost-of-modules/lib/helpers.js:64:17)
    at Object.getRootDependencies (/Users/me/.config/yarn/global/node_modules/cost-of-modules/lib/helpers.js:73:26)
    at Object.<anonymous> (/Users/me/.config/yarn/global/node_modules/cost-of-modules/lib/index.js:26:32)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)

My package.json is:

{
  "name": "gtest",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "gulp": "gulpjs/gulp#4.0",
    "gulp-cli": "^1.3.0"
  }
}

I am using npm 5.0.0, and I suspect that the issue relates to npm ls --json printing errors after printing the json (note that sync-exec channels both STDOUT and STDERR and returns the combination).

You should probably use:

const {spawnSync} = require('child_process')
const proc = spawnSync('npm', ['ls', '--json'])
console.log(JSON.parse(proc.stdout.toString()))
// ignore proc.stderr

Erroneous “JSON” output (note STDERR at end):

{
  "name": "gtest",
  "version": "1.0.0",
  "problems": [
    "invalid: gulp@4.0.0-alpha.2 /Users/me/Desktop/gtest/node_modules/gulp",
    "extraneous: glob-watcher@3.2.0 /Users/me/Desktop/gtest/node_modules/glob-watcher",
    "extraneous: undertaker@1.1.0 /Users/me/Desktop/gtest/node_modules/undertaker",
    "extraneous: vinyl-fs@2.4.4 /Users/me/Desktop/gtest/node_modules/vinyl-fs",
    "extraneous: node-pre-gyp@0.6.36 /Users/me/Desktop/gtest/node_modules/node-pre-gyp"
  ],
  "dependencies": {
    "...": "..."
  }
}
npm ERR! invalid: gulp@4.0.0-alpha.2 /Users/me/Desktop/gtest/node_modules/gulp
npm ERR! extraneous: glob-watcher@3.2.0 /Users/me/Desktop/gtest/node_modules/glob-watcher
npm ERR! extraneous: undertaker@1.1.0 /Users/me/Desktop/gtest/node_modules/undertaker
npm ERR! extraneous: vinyl-fs@2.4.4 /Users/me/Desktop/gtest/node_modules/vinyl-fs
npm ERR! extraneous: node-pre-gyp@0.6.36 /Users/me/Desktop/gtest/node_modules/node-pre-gyp

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:6
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
tvvigneshcommented, Mar 29, 2020

Same issue on my end. Works well in one project, but throws unexpected end of json in another. Screenshot below.

Screenshot from 2020-03-29 23-48-34

0reactions
michaelfarrell76commented, Feb 7, 2021
Screen Shot 2021-02-06 at 9 30 24 PM
Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught SyntaxError: Unexpected end of JSON input at ...
When you try to parse it as JSON it is converted to a string ( "" ), which is empty, so you reach...
Read more >
Unexpected end of JSON input Error in JavaScript - Stack Diary
The "Unexpected end of JSON input" error is a syntax error that occurs when the JSON you're trying to parse is incomplete or...
Read more >
Uncaught SyntaxError: Unexpected end of JSON ... - STechies
A common error encountered by JavaScript programmers is the Uncaught SyntaxError: Unexpected end of JSON input. This is usually observed when the coder...
Read more >
How to fix "SyntaxError: Unexpected token < in JSON at ...
This error occurs when you are trying to parse a string to JSON and the string is not parsable. In other words, it...
Read more >
Unexpected end of JSON input Error in JavaScript | bobbyhadz
The "Unexpected end of JSON input" error occurs when trying to parse invalid JSON using the JSON.parse or $.parseJSON methods. Trying to parse...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found