← Today I learned

npm breaks behind a TLS-inspecting VPN, curl doesn't

On a work VPN that re-signs HTTPS traffic with the company's own root certificate, npm install failed with:

UNABLE_TO_GET_ISSUER_CERT_LOCALLY

…while curl to the same URL worked fine.

The reason: curl on macOS trusts the system keychain, where IT installed the company root. Node ships its own CA bundle and ignores the keychain. NODE_USE_SYSTEM_CA=1 didn't help in my case.

What works is exporting the company root from the keychain and handing it to Node for that one command:

security find-certificate -a -c "Your Company Root" -p \
  /Library/Keychains/System.keychain ~/Library/Keychains/login.keychain-db > /tmp/vpn-ca.pem

NODE_EXTRA_CA_CERTS=/tmp/vpn-ca.pem npm install

NODE_EXTRA_CA_CERTS adds to Node's bundle rather than replacing it, so everything else keeps working. I keep it per-command rather than in my shell profile, so personal projects don't quietly trust a work certificate.

The simplest fix of all: disconnect from the VPN for personal stuff.