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.

Error: Unexpected end of JSON input when using empty package.json

See original GitHub issue

The version of ESLint you are using. 6.6.0

The problem you want to solve. When I have an empty package.json file in nested folder, near checked files, eslint gives error:

Error: Unexpected end of JSON input

There were similar issues previously - https://github.com/eslint/eslint/issues/11026#issuecomment-433744443, https://github.com/eslint/eslint/issues/7748 and there was no error in 5.16.0. Since 6.0.0 an error is thrown.

Your take on the correct solution to problem. It would be nice to have an option to disable this error. I tried to ignore this json file, but didn’t succeed.

This is useful for me because I want this file to be invalid on purpose so later I can check it.

Are you willing to submit a pull request to implement this change? Probably not, no free time to dive in atm.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
platinumazurecommented, Nov 15, 2019

I think we should treat invalid or empty object package.json the same way as we treat lack of configuration files of any other type. The only thing in package.json that counts as an ESLint configuration is an eslintConfig key and object. Anything else should not matter to ESLint.

I think we should throw if the eslintConfig value is invalid for some reason (e.g., it’s an array or string rather than an object). But, if we can’t even see an eslintConfig key, then there is no configuration for ESLint to look at and we know this for a fact. Throwing on invalid JSON (for package.json) is unnecessarily intrusive, in my opinion.

2reactions
mysticateacommented, Nov 15, 2019

When I try to lint tests folder, I believe eslint tries to read this nested tests/bad-json/package.json file to find eslint configuration and gives me an error.

You are right. In that case, you need /tests/bad-json in your .eslintignore, or a valid ESLint configuration file that has a higher priority than package.json such as /tests/bad-json/.eslintrc.yml.

Because ESLint reads /tests/bad-json/package.json when it entered /tests/bad-json directory in order to check if the config file change how ESLint traverses the subdirectory via RFC20 or RFC22. (so /tests/bad-json/package.json can have a setting that ignores/unignores /tests/bad-json/*.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

NPM Install Error:Unexpected end of JSON input while ...
The error happen when parsing one of the cache files, which have a json format. The cache is found at ~/.npm/_cacache (in linux)...
Read more >
npm ERR! Unexpected end of JSON input while parsing near
It needs to print the url it was trying to fetch, and not just say that it failed to parse some abstract json,...
Read more >
(Solved) Unexpected end of JSON input while parsing near '...'?
(Solved) Unexpected end of JSON input while parsing near '...'? · Error · Solution 1 - Delete npm cache · Solution 2 -...
Read more >
Unexpected end of JSON input error occurred when executing ...
The solution is simple. The yarn global cache need to be cleaned. yarn cache clean. Adding the --force parameter may be needed. There...
Read more >
[SOLVED] npm ERR! Unexpected end of JSON input while ...
This video is helpful to those people who are getting problems while installing the vue.js or Angular.js. We solved the npm ERR! Unexpected...
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