How to Disable Proxy in Installing Package Using npm

Posted on

This is an article related on the usage of npm. In the context of installing a specific package or module for Laravel using npm, there is an error related to the connection utilized by npm. So, in this article, the discussion is going to be focused on how to disable proxy in installing package using the npm. Below is the output generated upon executing the command for package or module installation using npm  :

npm install

Below is the full output generated :

root@hostname:/var/www/html/laravel# npm install
npm ERR! npm v3.5.2
npm ERR! code ECONNRESET
npm ERR! network tunneling socket could not be established, cause=connect ECONNREFUSED 10.242.
npm ERR! network This is most likely a problem with npm itself
npm ERR! network and is related to network connectivity
npm ERR! network In most cases you are behind a proxy or have a bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the 
npm ERR! network 'proxy' config is set properly. See: 'npm help config'

npm ERR! Please include the following file with any support request:
root@hostname:/var/www/html/laravel#

So, the problem is npm actually detects a configuration or a miss-configuration of network connection which prevent npm to be able to install package or module specified through the internet. The package or module specified in the context of this article is defined in composer.json which is located in the root folder of Laravel web-based application project. It is shown in the tree format output :

root@hostname:/var/www/html/laravel# tree -L 1
.
├── app
├── artisan
├── bootstrap
├── composer.json
├── composer.lock
├── config
├── database
├── logs
├── node_modules
├── package.json
├── phpunit.xml
├── public
├── readme.md
├── resources
├── routes
├── server.php
├── storage
├── tests
├── vendor
└── webpack.mix.js

12 directories, 8 files
root@hostname:/var/www/html/laravel# 

The content of the file named composer.json for adding or installing new package or module via npm is shown below :

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    ...
    ...,
    "dependencies" : {
        "laravel-elixir":"^3.0.0",
        "bootstrap-sass":"^3.0.0"
    }

}

It is not all of the content of composer.json written as shown above, the additional line of configuration for adding or installing new module or package is shown in the following line :

 "dependencies" : {
        "laravel-elixir":"^3.0.0",
        "bootstrap-sass":"^3.0.0"
 }

Check whether the problem is related on to the proxy :

root@hostname:/var/www/html/laravel# npm config list | grep proxy
http-proxy = "http://my.proxy.com:8080"
https-proxy = "http://my.proxy.com:8080"
proxy = "http://my.proxy.com:8080"
root@hostname:/var/www/html/laravel# 

As shown int the above output command of shown proxy configuration using npm command, an alternative solution for this problem is assuming that there are already proxy configuration and it is miss-configured or the proxy is not even needed. To disable the proxy configuration, below is the line of command which can be used to disable it :

root@hostname:/var/www/html/laravel# npm config set http-proxy=null
root@hostname:/var/www/html/laravel# npm config set https-proxy=null
root@hostname:/var/www/html/laravel# npm config set proxy=null
root@hostname:/var/www/html/laravel# npm config list | grep proxy
http-proxy = null
https-proxy = null
proxy = null
root@hostname:/var/www/html/laravel# 

After resetting the proxy configuration, just try to execute the ‘npm install’ command again to start installing package or module using npm.

 

One thought on “How to Disable Proxy in Installing Package Using npm

Leave a Reply