Node-gyp fetches headers from internet – not allowed because of firewall rules - node.js

I am trying to setup a simple node app in docker. The app needs to install npm package ibm_db. In that installation of ibm_db, node-gyp wants to download headers file from the internet which is not allowed under company firewall rule. Downloading npm packages works fine using a proxy.
https://nodejs.org/download/release/v16.14.2/node-v16.14.2-headers.tar.gz failed, reason: unable to get local issuer certificate
I am unsure of the best way forward here. Is it possible to install the headers.tar manually somehow?

Commit the specific version of the node-{NODE_VERSION}-headers.tar.gz file that you require into the repo, and do this:
echo "---> Set tarball"
NODE_VER=v16.13.1
npm config set tarball /{YOUR_PATH}/node-${NODE_VER}-headers.tar.gz
Then proceed with your npm install as you would normally.
https://github.com/nodejs/help/issues/3686#issuecomment-1011865975

Related

Npm download tarball failed due to broken url

I'm trying to install tileserver-gl to host my own OSM server on my windows machine.
At the moment, I have tried to install locally and via npm without much success.
The issue being, npm is unable to get 'mapbox-gl-native' from the specific web address.
I have seen similar issues to this, from this github issue thread , Link Here. In which they have provided an alternate download link.
I have tried to download the tileserver-gl files from the repo, manually put the required files inside, run npm install & npm install from source but to no avail.
There are online topics which said to use Node v4 , which i already tried on both Node v6 and Node v4 .
How do I fix this issue?

How can I install the latest version of Typescript without Internet (offline)?

I have Internet connection in my home and I can install the latest version of TypeScript with this command: npm install -g typescript , But unfortunately There is no Internet at my work place (in fact we are not allowed to use Internet).
Beside this I googled But It seems There is no offline installer for Typescript. My question is how can I handle this problem ?
I am totally new to npm and a step by step workaround would be appreciated .
There is an ugly solution: do npm install at home and copy the content of your globally installed packages folder to work.
If you want to be able to do npm install without access to the internet you will need to configure your own npm registry in your local network.
I've used Sinopia in the past when working offline. It works as a cache for npm allowing you to work off-line provided you have installed the required packages while having an internet connection.
As per https://www.npmjs.com/package/sinopia#installation you can install and configure Sinopia with the following steps:
# installation and starting (application will create default
# config in config.yaml you can edit later)
$ npm install -g sinopia
$ sinopia
# npm configuration
$ npm set registry http://localhost:4873/
# if you use HTTPS, add an appropriate CA information
# ("null" means get CA list from OS)
$ npm set ca null

nodejs "npm ERR! code SELF_SIGNED_CERT_IN_CHAIN"

I'm new to nodejs and npm. I'm trying to install log4js and this is the command for the install:
npm install log4js
I'm running this from Windows Command Line and I after a while of a marker spinning I get the following error:
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "log4js"
npm ERR! node v0.12.0
npm ERR! npm v2.5.1
npm ERR! code SELF_SIGNED_CERT_IN_CHAIN
npm ERR! self signed certificate in certificate chain
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <http://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! C:\srv\npm-debug.log
I tried doing npm config set ca="" like suggested here: http://blog.npmjs.org/post/78085451721/npms-self-signed-certificate-is-no-more but I'm still getting this error.
How can I solve this and install NPMs ?
Disabling strict-ssl mode will remove this error.npm set strict-ssl false
Since this is turning off SSL security, we should try this as last step if below two steps don't help.This issue can arise due to incompatibility between SSL certificate file of npm and node registry.
Try1) telling your current version of npm to use node's ca instead of built in canpm config set ca=""2) OR upgrading your version of npm
npm install npm -g --ca=null
I had the same problem on windows 10.
open windows powerShell and enter the following command:
npm config set registry http://registry.npmjs.org/
Then you can use:
npm install [your package]
As metioned by Akshay Vijay Jain above,
npm config set strict-ssl false
TURNING OFF SSL BEFORE INSTALLING THE LATEST VERSION:
Then install the latest version
npm install -g npm#latest
INSTALL SUCCESS!!:
See the screenshots added for clarity.
I'm new to npm as well. Besides the commands mentioned in your link I tried the following and it resolved my issues:
npm set strict-ssl false
disabled McAfee temporarily
Reference: Npm SELF_SIGNED_CERT_IN_CHAIN on Azure
While setting StrictSsl to false is an option, it compromises your npm security. I recommend not disabling it. The following instructions elaborate on Shreedhar's post to use the cafile. Though it's written from a Windows 10 machine perspective it can be adapted.
Our company uses SSL Inpsection via a proxy, so at the very least we need to include the SSL Inspection certificate. The following instructions assume you are able to use a modern web browser on the machine you are trying to use an externally reaching npm function.
From a command console, run the following: npm config list
Record the value for metrics-registry. This should be a URL.
Open a browser to the URL. As of writing this answer, it is https://registry.npmjs.org/
Open the certificate information for the site. For Chrome on Windows, this involves clicking the padlock icon to the left of the URL in the address bar and selecting the option Certificate.
Inspect the certification path. For me, there is our corporate CA and our SSL Inspection certificate.
Download each certificate as Base64 encoded into a .cer or .crt file.
Compile all the certificates as-is into one .cer or .crt file.
Place this file into a user folder. Though we have a network-based users folder I recommend and use a local machine based folder. Note the full path to this file.
From a command console, run the following: npm config set cafile "C:\Local\Path\To\cafile4npm.cer" modifying the path and file noted in step 8.
Run your npm install command.
Was getting same error when executed via Docker build.
Powershell execution, however, was error free. Then modified the dockerfile with following (as suggested above):
RUN npm config set ca=""
RUN npm set strict-ssl false
This fixed the cert chain issue.
In CentOS and other Linux distros you need to configure NPM to use your Certificate Authorities file:
npm config set cafile "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" -g
Obviously check the file exists and contains all CA Roots you may encounter (e.g. corporate proxy).
solve this problem with this command
npm config set strict-ssl=false
As of February 27, 2014, npm no longer supports its self-signed certificates. The following options, as recommended by npm, is to do one of the following:
Upgrade your version of npm
npm install npm -g --ca=""
-- OR --
Tell your current version of npm to use known registrars
npm config set ca ""
Update: npm has posted More help with SELF_SIGNED_CERT_IN_CHAIN and npm with more solutions particular to different environments
Read more here
Did you also tried settings cafile accommodating all pems in one file? npm add root CA
If you use proxy in your .npmrc file, I will suggest to set no_proxy environment variable with value of your <server IP address>
In my case, I had installed Fiddler, which has a self signed certificate which made the npm install go crazy.
See here how to remove the self signed Fiddler certificate How do you remove the root CA certificate that Fiddler installs
Our corporate environment inflicted this on us via some company cert chicanery, and this bit the Windows devs in both npm and git operations. For npm, the instructions provided previously by gregsonian (building a cert and pointing npm config to use it) still work well. (Win-10 for reference.) I prefer otherwise keeping SSL enabled.
None of the answers above helped out my situation. The culprit turned out to be the package agent-base pre 6.0.1. Indeed the owner admitted to shipping out self-signed certs in a test folder of his package. This forced a reinstall -D and -g but problem is still happening.
I found this cert by searching node_modules folder for *.pem.
Still working on getting npm caches to listen to me. Of course I'm the dummy right?
I'll post back additional findings.
Solution Found
7/7/2020
Our Angular application was upgraded from 8.3 to 10.0 today. Guess what? The errors disappeared. The root cause was someone published an unsigned cert that made it's way too deep in the NPM modules library. Even NPM 6.15 had it!
I tried many solutions here and none really worked for me. I tried updating npm but got either a timeout (when registry was set to http://registry.npmjs.org/), or a 403 Forbidden responce (when registry was set to https://registry.npmjs.org/)
In the end, realsing that my problem was caused by being behind a proxy, what did work for me in the end was:
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
(credit: https://stackoverflow.com/a/12832637/4191296)
I reinstalled node js and angular cli. It started working !!
You can disabled certificate validation for TLS connections:
NODE_TLS_REJECT_UNAUTHORIZED=0 npm install puppeteer
If you want to trust another certificate I think its better define the environment variable to trust the new certificate
NODE_EXTRA_CA_CERTS=<path to .pem file>
https://nodejs.org/api/cli.html#cli_node_extra_ca_certs_file
In my case I initially setup squid to proxy all http & https requests on my local ubuntu box, but was not aware that TLS version >= 1.3 requires ssl-bump, peek and splice TLS handshake features.
The following might help others understand what is going on "under the hood" so you can be confident that your fix is correct. If you don't use squid then skip that part, but take note of the final npm step.
Here are the steps to upgrade squid :
Install an upgrade patch provided by diladele . I also ran : apt upgrade after apt update
Use this tutorial to upgrade squid config to compliment the new ssl-bump features
Add env vars HTTP_PROXY=http://your.proxy.domain:3128 HTTPS_PROXY=http://your.proxy.domain:3128
Setup Firefox and/or Chrome to use squid as the http/https proxy
To enable npm ssl install, add the proxy ca-certificate.pem to the npm config
npm config set cafile /etc/squid/certs/squid-ca-cert.pem
After running step 5, npm install from https://registry.npmjs.org worked fine

Multiple NPM Registries When One is Behind VPN

At work we have an internal NPM Registry that houses our internal modules and passes through to npmjs.org for modules that are not in the registry. In order to use it I've added the following line to my ~/.npmrc file
registry=http://**privateurl**
Which works great while I'm at work or connected to the VPN but when I'm working on other stuff at home and not on the VPN running npm install fails because the private repository cannot be reached.
Is there a way I can add a timeout and a fallback to npmjs.org if the private npm repository cannot be found?
You could run npm install with --reg option from home forcing to fetch from npmjs.org
npm install express --reg https://registry.npmjs.org
... as mentioned in this SO Answer.

locally installing node npm packages

I am accessing internet under the wifi network(cyberoam) provided by our college. Whenever I am trying to install any npm package I am getting error like:
npm ERR! If you are behind a proxy, please make sure that the
npm ERR! 'proxy' config is set properly. See: 'npm help config'
ECONNREFUSED
I haven't set up any proxies on my Linux machine then also I'm getting error like this.
Is there any way to install those packages locally i.e how can I use them directly without installing them as npm packages.
Yes it is possible but I usually don't do that. For a quick and dirty solution:
Search for the packages repos in github
Checkout them to your local machine
And copy each one to the ./node_modules directory inside your node.js application folder.
In the future I certainly recommend you to use npm instead.

Resources