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

前端 未结 30 1853
孤街浪徒
孤街浪徒 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条回答
  • 2020-11-22 10:53

    Try setting

    npm config set strict-ssl false

    and then try running,

    npm install -g @angular/cli

    0 讨论(0)
  • 2020-11-22 10:54

    These commands worked for me

    sudo npm cache clean --force
    
    sudo npm cache verify
    
    sudo npm i npm@latest -g
    
    0 讨论(0)
  • 2020-11-22 10:57

    I got error (file already exists --force to overwrite) after running the following code:

    npm cache clean --force
    npm install -g @angular/cli
    

    I solved it using :

    npm i -g --force npm
    

    Make sure to run the first commands to flush the cache of npm.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-22 10:59

    Solution

    npm cache clean --force
    

    For Windows : go to C:\Users\username\AppData\Roaming\npm-cache
    Delete all files and run

    npm install && npm start
    
    0 讨论(0)
  • 2020-11-22 10:59
    npm cache clean --force
    npm update
    

    Do not forget to do "npm update". it is very important step .

    0 讨论(0)
提交回复
热议问题