node icon indicating copy to clipboard operation
node copied to clipboard

Nodejs 4 introduces UNABLE_TO_GET_ISSUER_CERT_LOCALLY error for users behind company firewalls

Open greenmountains opened this issue 11 years ago • 27 comments

Nodejs 4 appears to introduce an UNABLE_TO_GET_ISSUER_CERT_LOCALLY error for users behind a company firewall.

Npm install & other commands no longer work after update from Nodejs 0.12 to Nodejs 4 or 5. After discussion on the npm forums, current thought is that this may be an issue in Node rather than Npm.

See https://github.com/npm/npm/issues/9580. Also https://github.com/npm/npm/issues/10125 https://github.com/npm/npm/issues/9906

This issue is preventing our team from upgrading to Nodejs 4 or 5. Any suggestions welcome.

Thanks

greenmountains avatar Nov 10 '15 18:11 greenmountains

Node.js 7.3.0 added NODE_EXTRA_CA_CERTS environment variable for you to pass the CA certificate file. It is safer than disabling certificate verification using NODE_TLS_REJECT_UNAUTHORIZED.

$ export NODE_EXTRA_CA_CERTS=[your CA certificate file path]

This solution works with me for node-gyp. npm config set cafile does not work.

cltsao avatar Nov 07 '17 14:11 cltsao

I'm still seeing this because of a node-gyp dependency and my company uses self-signed certificates.

My .npmrc file:

strict-ssl=false
cafile=C:/Tools/mycerts.pem
registry=https://registry.npmjs.org/
proxy=companyproxy
http-proxy=companyproxy
https-proxy=companyproxy
NODE_TLS_REJECT_UNAUTHORIZED=0

I've also tried various permutations with these, with npm and with yarn: ca= vs NODE_EXTRA_CA_CERTS=C:/Tools/mycerts.pem vs cafile=C:/Tools/mycerts.pem with and without NODE_TLS_REJECT_UNAUTHORIZED

Below magically worked once with yarn and then I removed 1 npm package later and it started failing again and I haven't gotten it to work since (maybe an update by the network team???)

strict-ssl=false
NODE_EXTRA_CA_CERTS=C:/Tools/mycerts.pem
registry=https://registry.npmjs.org/
proxy=companyproxy
http-proxy=companyproxy
https-proxy=companyproxy

Info:

  • Win 10 x64
  • node v8.9.1
  • npm 5.5.1
  • yarn 1.3.2
  • Using nvm and node_modules is stored under C:\Tools

Below is my stack trace if anyone can help...

error C:\Development\projects\myproject\node_modules\sharp: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: C:\Development\projects\myproject\node_modules\sharp
Output:
C:\Development\projects\myproject\node_modules\sharp>if not defined npm_config_node_gyp (node "C:\Tools\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild

 )
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | win32 | x64
gyp info spawn C:\Users\username\.windows-build-tools\python27\python.exe
gyp info spawn args [ 'C:\\Tools\\nvm\\v8.9.1\\node_modules\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=2015',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Development\\projects\\myproject\\node_modules\\sharp\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Tools\\nvm\\v8.9.1\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\username\\.node-gyp\\8.9.1\\include\\node\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\username\\.node-gyp\\8.9.1',
gyp info spawn args   '-Dnode_gyp_dir=C:\\Tools\\nvm\\v8.9.1\\node_modules\\npm\\node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=C:\\Users\\username\\.node-gyp\\8.9.1\\<(target_arch)\\node.lib',
gyp info spawn args   '-Dmodule_root_dir=C:\\Development\\projects\\myproject\\node_modules\\sharp',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'C:\\Development\\projects\\myproject\\node_modules\\sharp\\build',
gyp info spawn args   '-Goutput_dir=.' ]
sharp: https://github.com/lovell/sharp-libvips/releases/download/v8.6.1/libvips-8.6.1-win32-x64.tar.gz download failed: unable to get local issuer certificate
gyp: Call to 'node -e "require('./binding').download_vips()"' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (C:\Tools\nvm\v8.9.1\node_modules\npm\node_modules\node-gyp\lib\configure.js:336:16)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 10.0.15063
gyp ERR! command "C:\\Tools\\nodejs\\node.exe" "C:\\Tools\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Development\projects\myproject\node_modules\sharp

I've also tried downloading that package's source code into my company's internal GitLab and configuring my env to look there, but that still fails with the same unable to get local issuer certificate error :(

tcjcodes avatar Feb 23 '18 01:02 tcjcodes

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] normally.

ronaldomoreira avatar May 21 '18 19:05 ronaldomoreira

I use following on Windows SET NODE_TLS_REJECT_UNAUTHORIZED=0 Could not figure out why cafile doesn't work

ygizhitsa avatar Dec 04 '18 18:12 ygizhitsa

I have found a solution as "npm config set registry http://registry.npmjs.org/ "

28vishalrawal avatar Jan 16 '19 08:01 28vishalrawal

Assuming that your SSL CA configuration is done done properly and you configured there the custom CA, you can force node to use the openssl config with the node runtime option --use-openssl-ca See #5620

zioalex avatar Sep 22 '21 14:09 zioalex

I faced this issue but for a different reason. Putting it here for future.

  • installed node via homebrew, openssl is dependency
  • openssl creates the CA file using the system one
  • upgraded to macOS 15
  • I think the system CA files changed or something else happened
  • it broke the pem file
  • solution is to reinstall ca-certificates formula

brew uninstall --ignore-dependencies ca-certificates brew reinstall node

pantheraleo-7 avatar Oct 12 '24 12:10 pantheraleo-7