How to configure npm proxy for the company's Zscaler settings? - npm

0
In my company I can't download the node modules via npm, because the connection is being refused. We use a Zscaler with a .pac config file. I tried to configure the proxy via various tutorials
Is there a way to make npm install (the command) to work behind proxy?
https://www.jhipster.tech/configuring-a-corporate-proxy/
but I don't get it to work. When I type
npm --proxy http://username:password#cacheaddress.com.br:80 install packagename
it tells me "event not found", when I type the password. If I leave the password field empty, I get
npm ERR! 418 I'm a teapot - GET http://registry.npmjs.org/electron - got unknown host (registry.npmjs.org:80)

Related

Cannot load a package using NPM - local certificate error

Apologies if this is a repeat question, but I am new to this. I have installed nodeJS and am trying to install hardhat. I have a Windows 10 laptop.
I followed the instructions here: https://hardhat.org/tutorial/setting-up-the-environment
I am trying to run the following code:
mkdir hardhat-tutorial
cd hardhat-tutorial
npm init --yes
npm install --save-dev hardhat
Then I get the following errors:
npm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLY
npm ERR! errno UNABLE_TO_GET_ISSUER_CERT_LOCALLY
npm ERR! request to https://registry.npmjs.org/hardhat failed, reason: unable to get local issuer certificate
When I search this online it says to try the following solutions:
npm config set strict-ssl false
OR
npm config set registry http://registry.npmjs.org/
I've done both and rebooted the PC and it doesn't make a difference. Anyone got any ideas of what I can do to resolve this?
Thanks
John
You are running from behind a "deep inspection" web proxy, which issues fake SSL certificates to allow it to inspect your traffic, and although there are probably automated systems to make your browser trust the root CA cert that issues these certificates, npm is not configured to trust that CA.
You should be able to get the CA cert from your browser, the system keychain, or your IT department, and then configure npm to use it with npm config set cafile /path/to/cert.pem
even if you don't know where the corporate certificate is located you can solve it for a single terminal use by running set NODE_TLS_REJECT_UNAUTHORIZED=0 before running the npm commands it will work for the current terminal session.
or you can run setX NODE_TLS_REJECT_UNAUTHORIZED 0 /m once
beware this option as security risks!
to cancel this setting you should run REG delete "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /F /V NODE_TLS_REJECT_UNAUTHORIZED .
the best way to solve the problem will be to find the corporate certificate and run the following command SetX NODE_EXTRA_CA_CERTS "path/to/certificate" /m when you change path/to/certificate by the full path.
Turning off strict ssl: npm config set strict-ssl=false
Changing the registry to http instead of https: npm config set registry http://registry.npmjs.org/
Changing my cafile setting: npm config set cafile /path/to/your/cert.pem
Stop rejecting unknown CAs: set NODE_TLS_REJECT_UNAUTHORIZED=0

Force NPM to skip package already installed from another source

I'm trying to npm install a package from a heavily proxied Enterprise computer. One of the dependencies of this package tries to install via GitHub, which throws a 407 error.
npm ERR! /usr/bin/git ls-remote -h -t https://github.com/ethereumjs/ethereumjs-abi.git
npm ERR!
npm ERR! fatal: unable to access 'https://github.com/ethereumjs/ethereumjs-abi.git/': Received HTTP code 407 from proxy after CONNECT
I've discussed this with the team that manages these servers- even with proper proxy authentication, access to sites outside of internal registries are very uncommon as a security measure.
As an alternative, I found the package on the NPM registry, and successfully installed it using the internal mirror we have. However, it still tries to install the GitHub version as a dependency of the first package, and then the installation fails. Is there any way to prevent this? I think I've seen something about editing the package's package.json to remove the dependency, but I don't have any experience with this, so I'll only do it if it's the only option to prevent this. Thank you

Cannot login into Verdaccio

I have just installed Verdaccio on my computer. I have changed nothing in the config file, apart from adding proxy_related info:
http_proxy: http://proxy.ip:8080
https_proxy: https://proxy.ip:8080
no_proxy: localhost,127.0.0.1
After starting the process, I have tried to login to the registry from the library project workspace
npm adduser --registry http://localhost:4873
But I get this error:
npm ERR! 503 Service Unavailable - POST http://localhost:4873/-/v1/login
If I try to reach http://localhost:4873/ from my browser, I can see the Verdaccio webpage.
What am I doing wrong?
I don't know what kind of environment you are trying this (work, home, etc.) but, for me, my problem was that behind a corporate firewall I have to configure the NPM proxy (http and https), so adding the localhost as an exception to noproxy config attribute of NPM, it worked for me.
npm config set noproxy localhost
Try to change yours, from no_proxy to noproxy, maybe it is simple as that.

create-react-app-typescript failed with Proxy Authentication required error while creating app

I am working in corporate premise. I am trying to create react app with typescript but it failed with below error:
D:\learning\reactjs>create-react-app my-app --scripts-version=react-scripts-ts
Creating a new React app in D:\learning\reactjs\my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripemphasized textts-ts...
npm ERR! code E407
npm ERR! 407 Proxy Authentication Required: react-scripts-ts#latest
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\kalpanap\AppData\Roaming\npm-cache_logs\2018-02-21T02_33_17_410Z-debug.log
Aborting installation.
*npm install --save --save-exact --loglevel error react react-dom react-**scripts-ts has failed.*
Deleting generated file... package.json
Deleting my-app / from D:\learning\reactjs
Can anyone help to fix this problem?
Even I have updated npm config proxy and https-proxy to office n/w proxy. After this change only I was able to successfully run the npm install command.
How can I create-react-app with passing proxy parameters?
Thanks in advance
Your company's proxy must be not allowing you to access the setup.
Use the following two commands from command-promt
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
In place of "proxy.company.com", use your proxy address that you are using.
You can find your proxy at
IE Browser -> Internet Options -> Connections tab -> LAN Settings.

Jfrog Artifactory does not work with NPM packages from #types (NPM organization/scope)

We use artifactory for npm, bower etc for our projects. now we want to use new feature TypeScript type definitions to fetch the npm package as #types/jasmine (NPM organization/scope) through artifactory but when we try to access it we get http 400
$ npm install -g protractor
npm http 400 http://artifactory/artifactory/api/npm/npm-virtual/#types%2fjasmine
we are able to access the link directly on npm public repo but. it doesn't work through artifactory. is it still not supported . is there a workaround or fix.
From the Artifactory user guide:
Npm 'slash' character encoding
By default, the npm client encodes slash characters ('/') to their ASCII representation ("%2f") before communicating with the npm registry. If you are running Tomcat as your HTTP container (the default for Artifactory), this generates an "HTTP 400" error since Tomcat does not allow encoded slashes by default. To avoid this error when using npm scope packages, you can override this default behavior by defining the following property in the catalina.properties file of your Tomcat:
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true