npm ERR! Unexpected token < in JSON

Quang Nguyen
Sep 3, 2018 · 1 min read

Have you ever gotten that error while working on your code? Seems weird right? how does that even happen? You have just installed some modules using npm, write some code, pushed it on for a code review from your peers. Then everyone checks your code and gives it the green light to merge into master. It goes into master, and every one pull from master. All of a sudden every one’s project can not serve on localhost because of this error,

npm ERR! Unexpected token < in JSON

So you and your fellow engineers are scratching your heads wondering what this means. One of you tries to go into the package.json to find the < token because the error says so. No luck. Your package.json looks pristine. No errors to be found.

What do you do now? Worry not my friends. There are a couple of things you can try.

Open up terminal if you are not on it already and go into your project’s root folder where your package-lock.jon is at and

  1. run this command:
rm -f package-lock.json && npm install

2. if that doesn’t work, try

rm -rf node_modules && npm install

and if doing one of those doesn’t work, you can try doing:

rm -f package-lock.json && rm -rf node_modules && npm install

and if all else fails, Google is your best friend!

quangtn0018

Just my findings and techniques that I’ve learned from working and doing side projects on all things software engineering related

Quang Nguyen

Written by

Software Engineer

quangtn0018

Just my findings and techniques that I’ve learned from working and doing side projects on all things software engineering related

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade