yarn icon indicating copy to clipboard operation
yarn copied to clipboard

yarn install - An unexpected error occurred: "/Users/[username]/package.json: Unexpected end of JSON input"

Open tilakbhanu opened this issue 6 years ago • 4 comments

Using Mac - OS Catalina - Version 10.15.7 I have installed yarn using brew.
Cloned my project to the local folder and ran yarn install in my local directory where package.json resides.

error An unexpected error occurred: "/Users/[myusername]/package.json: Unexpected end of JSON input". info If you think this is a bug, please open a bug report with the information provided in "/Users/[Myusername]/[My local folder where project cloned]/yarn-error.log".

I don't understand why yarn is looking at my root directory to find package.json. Here is the partial output of error.log file to investigate the issue.

Arguments: /usr/local/Cellar/node/14.13.1/bin/node /Users/[username]/.yarn/bin/yarn.js install

PATH: /Users/[username]/.yarn/bin:/Users/[username]/.config/yarn/global/node_modules/.bin:/Users/[username]/.sdkman/candidates/java/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands

Yarn version: 1.22.5

Node version: 14.13.1

Platform: darwin x64

Trace: SyntaxError: /Users/[username]/package.json: Unexpected end of JSON input at JSON.parse () at /Users/[username]/.yarn/lib/cli.js:1625:59 at Generator.next () at step (/Users/[username]/.yarn/lib/cli.js:310:30) at /Users/[username]/.yarn/lib/cli.js:321:13

npm manifest: { "name": "projectname", "version": "0.1.0", "description": "Project name App", "private": true, "license": "MIT", "author": "", "keywords": [ "gatsby" ],

--- all of my dependencies }

yarn manifest: No manifest

Lockfile: No lockfile

tilakbhanu avatar Oct 12 '20 05:10 tilakbhanu

Don't forget that if you get this error on mac or windows it can be because you have an empty package.json in your home directory /Users/[username]/package.json.

If you have the empty file there just delete it and you are on track again.

medesko avatar Nov 19 '20 08:11 medesko

I don't understand why yarn is looking at my root directory to find package.json.

It's to figure out if you're in a workspace or not and if your package.json is invalid it will throw

merceyz avatar Jan 02 '21 13:01 merceyz

Thanks this helped a lot @medesko !!

adiraj297 avatar Jan 04 '21 04:01 adiraj297

Don't forget that if you get this error on mac or windows it can be because you have an empty package.json in your home directory /Users/[username]/package.json.

If you have the empty file there just delete it and you are on track again.

Not a problem in my case :( I don't have any package.json in home directory.

My OS is Windows 10.

The only files in my /Users/[username]/ are these:

Screenshot_2

Luk-kar avatar Apr 19 '21 16:04 Luk-kar