Angular 6项目运行时node-pre-gyp与grpc报错求助
Hey, I’ve dealt with this exact grpc installation headache before—those certificate and pre-built binary mismatch errors are the worst. Let’s break down what’s going wrong and fix it step by step:
First, the core issues from your error log:
self signed certificate in certificate chain: npm is hitting a certificate issue when trying to download grpc’s pre-built binaries- Pre-built binaries don’t exist for your Node 8.9.4 (node-v57 ABI) and grpc@1.20.0, so it falls back to source compilation which fails too
Here are the fixes that worked for me:
1. Bypass certificate checks temporarily (dev environment only!)
Since the certificate error is blocking the download, you can tell npm to skip strict SSL checks for this install. Run this command:
npm install --unsafe-perm --strict-ssl=false
--unsafe-perm: Lets npm run the install scripts with root permissions, which helps with source compilation--strict-ssl=false: Skips the SSL certificate validation that’s causing the block
2. Use a mirrored binary source (great for regions with limited access)
If you’re in a region where accessing the official grpc binaries is tricky, use a mirror that has pre-built binaries for your Node version. For example, set up the Taobao mirror:
npm config set grpc_node_binary_host_mirror=https://npm.taobao.org/mirrors/grpc/
Then run your install again:
npm install
This mirror often has pre-built binaries for older Node versions that the official repo might not have anymore.
3. Upgrade your Node.js version (if your project allows)
Node 8.9.4 is pretty outdated, and grpc@1.20.0 has better support for newer LTS versions like Node 10.x. If your Angular 6 project can handle it:
- Upgrade Node to the latest Node 10 LTS (you can use nvm to manage versions easily:
nvm install 10 --lts) - Delete your
node_modulesandpackage-lock.jsonagain, then runnpm install
Newer Node versions will have matching pre-built binaries for grpc@1.20.0, avoiding the source compilation fallback entirely.
4. Fix the source compilation environment
If you have to stick with Node 8.9.4, make sure your system has all the tools needed for node-gyp to compile grpc from source:
- Windows: Install the Windows Build Tools via npm:
This installs Visual Studio Build Tools and Python, which are required for compiling native modules.npm install -g windows-build-tools - Mac: Install Xcode Command Line Tools:
xcode-select --install - Linux: Install gcc, make, and other build essentials:
sudo apt-get update && sudo apt-get install build-essential
Before trying any of these, make sure you’ve fully cleaned your existing setup (since you already tried this, but it’s good to double-check):
# For macOS/Linux rm -rf node_modules package-lock.json npm cache clean --force # For Windows rmdir /s /q node_modules del package-lock.json npm cache clean --force
内容的提问来源于stack exchange,提问作者Marvin Ericson

