NPM Installation Issue: JSON Parsing Error with Webpack Plugin

Problem Overview

I am facing an issue when I attempt to create a new Angular 5 project. Each time I run the installation command for the Angular CLI globally, I encounter a JSON parsing error that halts the process.

My Setup

  • Node version: 8.9.2
  • NPM version: 5.5.1

Command I Execute

npm install -g @angular/cli

Received Error

npm ERR! Unexpected end of JSON input while parsing near '...nt-webpack-plugin':'0'
npm ERR! You can find the complete log of this operation at:
npm ERR!     C:\Users\Aashitec\AppData\Roaming\npm-cache\_logs\2017-12-06T13_10_10_729Z-debug.log

This seems to occur when npm tries to read some JSON data related to a specific webpack plugin. I tried clearing the npm cache, yet the issue continues. Has anyone else experienced this error? What could be the underlying cause of this JSON parsing problem during the installation?

Hit this same problem with Node 8.x last year. Network interruptions during downloads leave broken JSON files in npm’s cache. After clearing cache, run npm config set registry https://registry.npmjs.org/ to make sure you’re hitting the right registry, then try installing with --verbose to see exactly where it breaks. If that doesn’t work, switch to yarn for the global install - yarn global add @angular/cli - since it handles corrupted cache better. Usually it’s flaky internet or antivirus messing with downloads.

Hit this same error two months back setting up my dev environment on Windows. Wasn’t just the package cache - turned out to be corrupted registry entries in npm’s metadata cache. npm cache clean --force didn’t fix it. Had to manually delete the whole npm-cache folder from AppData, then run npm cache verify to rebuild everything. Angular CLI installed fine after that. Pretty sure the corruption happened when a previous package install got interrupted or timed out.

same thing happened to me a few weeks back. update npm first: npm install -g npm@latest, then try installing angular again. old npm versions sometimes can’t handle newer package metadata. if it still doesn’t work, use npx instead: npx @angular/cli new my-project - no global install needed.