javascript icon indicating copy to clipboard operation
javascript copied to clipboard

Unexpected end of JSON input

Open kapilsriram opened this issue 2 years ago • 20 comments

I am facing similar issue as mentioned in https://github.com/airbnb/javascript/issues/2540

whenever I run "eslint ." i am thrown "Unexpected end of JSON input" image

kapilsriram avatar Dec 27 '22 11:12 kapilsriram

What version of everything are you using? eslint 8.2 is out of date, try with eslint latest, and make sure you're on the latest of eslint-config-airbnb as well.

ljharb avatar Dec 27 '22 17:12 ljharb

i use 19.0.4 of eslint-config-airbnb and v8.30.0 of eslint. Still the same issue. this is what i have in my eslint.json

extends": ["eslint:recommended","airbnb/whitespace"],

if i replace "airbnb/whitespace" with "airbnb" or even "airbnb/hooks" the issue is resolved. but wont work with whitespace for some reason

kapilsriram avatar Dec 28 '22 10:12 kapilsriram

image

kapilsriram avatar Dec 28 '22 10:12 kapilsriram

i have 2 different projects, with same issue, in one project, it opens "airbnb/whitespace-async.js" file in my notepad whenever i run "npm run lint" or "eslint ."

kapilsriram avatar Dec 28 '22 10:12 kapilsriram

The way the eslint-config-airbnb/whitespace file works is it executes https://unpkg.com/browse/[email protected]/whitespace-async.js - which is an executable node program - and it outputs JSON.

If that file is being opened in your editor then perhaps the executable bit isn't set properly on that file, or perhaps something about your system isn't supporting execSync of an executable JS file. It's possible this happens on any Windows machine, but I'd be pretty surprised if you were the first Windows user to use the whitespace config.

If it's a problem on all Windows machines, then we might need to change the approach we use to execute the whitespace-async file.

ljharb avatar Dec 28 '22 19:12 ljharb

the problem didnt exist in older versions, only in the latest versions we r facing the issue. Previously we used 18.2.0 with typescript 3.9.10

kapilsriram avatar Dec 29 '22 13:12 kapilsriram

yes, this technique was introduced to be compatible with eslint 8.

ljharb avatar Dec 29 '22 18:12 ljharb

is it possible to fix this thing? or can give me a hint of how to get around this, I can give a try and probably will contribute the update

kapilsriram avatar Dec 30 '22 14:12 kapilsriram

I believe that what's required is either finding a package that can sync exec a node file on linux/mac and windows - or, detecting windows, and using an alternative sync approach on windows (all in the whitespace file, to exec the whitespace-async file).

ljharb avatar Dec 30 '22 17:12 ljharb

image by adding "node " to the command, the issue seized, is this the expected functionality? we are only trying to run the js file in node isnt?

kapilsriram avatar Jan 02 '23 08:01 kapilsriram

i don't know what you mean by "seized" here - but certainly if running it directly with node fixes the problem, that might work.

ljharb avatar Jan 02 '23 19:01 ljharb

i mean stopped. cool. I was just checking if "node " does the same thing as it was doing previoulsy

kapilsriram avatar Jan 03 '23 08:01 kapilsriram

Yes, it should be unnecessary, but it also doesn't hurt. Want to make a PR?

ljharb avatar Jan 03 '23 17:01 ljharb

yep sure.

kapilsriram avatar Jan 06 '23 10:01 kapilsriram

I faced the very same issue recently. So, the problem was the line #!/usr/bin/env node here

My fix:

  1. Create/update the symlink at /usr/bin ln -s <path_to_your_nodejs> /usr/bin/node
  2. Check permission(I just set 777 and that's all)

I hope it'will work for someone else

meta-panic avatar Feb 12 '23 15:02 meta-panic

@kapilsriram hi! Maybe my workaround could help you

meta-panic avatar Feb 12 '23 20:02 meta-panic

@meta-panic could you please elaborate..? I am facing the same issue .

Oms-343 avatar Mar 04 '23 14:03 Oms-343

@kapilsriram your solution helped. Thankyou👍

Oms-343 avatar Mar 06 '23 07:03 Oms-343

Looks like the fix worked for many people.

IMHO, The PR and the issue both can get resolved.

postmeback avatar May 29 '23 13:05 postmeback