NPM Install Take So Long and Sometimes Looks Hang

    I am currently using NPM for developing ReactJS and I just test sample code from git. Eventually when I try to install packages for the first time its work normally, because of some reason I try to upgrading some package and reinstall it but the installation process looks hang.

The package that I try to reinstall is react-scripts. Here is some advice from StackOverflow:

  • Try to remove package-lock.json (https://stackoverflow.com/questions/50522376/npm-install-hangs-on-loadidealtreeloadalldepsintoidealtree-sill-install-loadid)
  • Try to using unix command line (e.g. git bash). (https://stackoverflow.com/questions/64290462/npx-create-react-app-takes-too-long-every-time)
  • Try to using `npm install <package> --verbose` to know the progress
Walkthrough:
    I just try install using verbose and hang after checking several packages. I find the pattern which different between the package that pass the check and package that hang, it was the status code (HTTP Response), package that pass check will response with status code 304 (Not Modified) and for the hang one there is no response. I search some solution on StackOverflow and found this 'https://stackoverflow.com/questions/45433130/npm-install-gets-stuck-at-fetchmetadata' that lead me to checking the npm installation registry domain (registry.npmjs.org) which is the global config of my npm registry.

Figure out:
    I try the url of hang package in the browser, for the first time it return ERR_NETWORK_CHANGED that I know because of DNS Server not correctly response my request. After that I try to ping to make sure my connection and it was fine.

Resolve:
    After several test and check, I try to add static route to my hosts list that direct to the npm registry url. I add this line  at the end of file /etc/hosts.
104.16.20.35 registry.npmjs.org
This is the end because when I try install again (with verbose) it was really smooth and the log is show that not only response with status code of 304, it also show the status code of 200.

Tidak ada komentar:

Posting Komentar