Analysis of npm error ENOTFOUND npm ERR! network request to https://npm.***.com/*** failed and the role of the .npmrc file

1. npm reports an error:

  Looking at a project today, an error was reported when executing npm install to install dependencies:

84 error code ENOTFOUND
85 error errno ENOTFOUND
86 error network request to https://npm.***.com/@umijs%2fpreset-react failed, reason: getaddrinfo ENOTFOUND npm.***.com npm.***.com:443
87 error network This is a problem related to network connectivity.
87 error network In most cases you are behind a proxy or have bad network settings.
87 error network
87 error network If you are behind a proxy, please make sure that the
87 error network 'proxy' config is set properly.  See: 'npm help config'

ENOTFOUND   npm ERR! network request to failed

  It means that the registration address of this mirror cannot be found.

  Why is there such a situation? Aren’t all npm installation mirror addresses downloaded from npm? So look at the project structure and found the .npmrc file

2. The role of the .npmrc file

  There may be a .npmrc file in the root directory of some projects. When you click to open it, there is only one sentence: registry=

  Is the npm warehouse mirror address

  In npm i, if there is this file in the project root directory, node_modules will be automatically installed from this mirror address, and there is no need to manually set the mirror address.

  So the problem is that there is a problem with the mirror address in the .npmrc file, just delete this file.

3. npm configuration and .npmrc file

(1) npm cli provides the npm config command for npm related configuration, through npm config ls -l you can view all the configurations of npm, including the default configuration.

(2) npm config set to modify the configuration items, after using the command configuration, all the comments in the configuration file will be deleted

(3) Some common configurations:

  proxy, https-proxy: Specify npm to use a proxy

  registry specifies the source of the npm download and installation package. Default:

npm config set prefix $dir

(4) npmrc file: In addition to using the npm config command of cli to display and modify the npm configuration, you can also directly modify the configuration through the .npmrc file.

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *