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

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

Author: Fantashit

1 thought on “yarn install – An unexpected error occurred: “/Users/[username]/package.json: Unexpected end of JSON input”

  1. 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.

Comments are closed.