NPM Install Error:Unexpected end of JSON input while parsing near '…nt-webpack-plugin“:”0'

前端 未结 30 2261
孤街浪徒
孤街浪徒 2020-11-22 10:20

When Creating a new Angular 5 project:

node version: 8.9.2

npm version: 5.5.1

My Command is

npm install -g @angular/cli
30条回答
  •  旧时难觅i
    2020-11-22 10:59

    Solution:

    npm cache clean --force
    

    then try again to create your app (here when creating a react app) or install what you were about to install.

    create-react-app myproject
    

    (creating react app)[same npm problem that can occur in different operation]

    npm install -g @angular/cli@latest
    

    (installing angular cli (or installing anything else))

    It will work.

    explanation:

    That's a problem related to npm, it's about the cache that get corrupt. Even though in newer versions of npm they implemented self healing, which normally guarantee no corruption, but it seem it's not that efficient. Forcing clean cache resolve the problem.

    The error happen when parsing one of the cache files, which have a json format. The cache is found at ~/.npm/_cacache (in linux) and %AppData%/npm-cache (windows). For my current npm version and when i checked, there was three directories.

    if you check the first or the second, the structure is as follow

    And each cache file have a json format (and that what get parsed)

    Here a good link from the doc: https://docs.npmjs.com/cli/cache

    [Update] Also if it happen that this didn't solve it, you may check this answer here https://stackoverflow.com/a/50191315/7668448 it show how you can change the npm registry, that can be helpful. Check and see.

提交回复
热议问题