NPM China Acceleration Configuration

Configure NPM domestic mirror sources to solve slow Claude Code and Node.js package installation issues and improve development experience.

Why Need Acceleration Configuration?

Due to network environment restrictions, downloading packages directly from the official NPM repository may encounter:

  • Slow download speed
  • Connection timeout
  • Installation failure

Configuring domestic mirror sources can significantly improve installation speed and success rate.

Mirror Source Selection

Recommended domestic mirror sources:

Mirror SourceURLMaintainerRecommendation
Taobao Mirrorhttps://registry.npmmirror.comTaobao Team⭐⭐⭐⭐⭐
Tencent Mirrorhttps://mirrors.cloud.tencent.com/npmTencent Cloud⭐⭐⭐⭐
Huawei Mirrorhttps://mirrors.huaweicloud.com/repository/npmHuawei Cloud⭐⭐⭐⭐
USTC Mirrorhttps://npmreg.proxy.ustclug.orgUSTC LUG⭐⭐⭐

Configuration Methods

# Set Taobao mirror
npm config set registry https://registry.npmmirror.com

# Verify configuration
npm config get registry

# Test installation speed
npm install -g @anthropic-ai/claude-code

Method 2: Use .npmrc File

Create .npmrc file in user home directory or project root directory:

registry=https://registry.npmmirror.com
disturl=https://npmmirror.com/dist
chromedriver_cdnurl=https://npmmirror.com/mirrors/chromedriver
couchbase_binary_host_mirror=https://npmmirror.com/mirrors/couchbase/v{version}
debug_binary_host_mirror=https://npmmirror.com/mirrors/node-inspector
electron_mirror=https://npmmirror.com/mirrors/electron/
flow_binary_host_mirror=https://npmmirror.com/mirrors/flow/v
fse_binary_host_mirror=https://npmmirror.com/mirrors/fsevents
fuse_bindings_binary_host_mirror=https://npmmirror.com/mirrors/fuse-bindings/v{version}
git4win_mirror=https://npmmirror.com/mirrors/git-for-windows
gl_binary_host_mirror=https://npmmirror.com/mirrors/gl/v{version}
grpc_node_binary_host_mirror=https://npmmirror.com/mirrors
hadoop_js_binary_host_mirror=https://npmmirror.com/mirrors/hadoop-js/v{version}
leveldown_binary_host_mirror=https://npmmirror.com/mirrors/leveldown/v{version}
leveldown_hyper_binary_host_mirror=https://npmmirror.com/mirrors/leveldown-hyper/v{version}
mknod_binary_host_mirror=https://npmmirror.com/mirrors/mknod/v{version}
node_sqlite3_binary_host_mirror=https://npmmirror.com/mirrors
nodegit_binary_host_mirror=https://npmmirror.com/mirrors/nodegit/v{version}/
operadriver_cdnurl=https://npmmirror.com/mirrors/operadriver
phantomjs_cdnurl=https://npmmirror.com/mirrors/phantomjs
profiler_binary_host_mirror=https://npmmirror.com/mirrors/node-inspector/
puppeteer_download_host=https://npmmirror.com/mirrors
python_mirror=https://npmmirror.com/mirrors/python
rabin_binary_host_mirror=https://npmmirror.com/mirrors/rabin/v{version}
sass_binary_site=https://npmmirror.com/mirrors/node-sass
sodium_prebuilt_binary_host_mirror=https://npmmirror.com/mirrors/sodium-prebuilt/v{version}
sqlite3_binary_site=https://npmmirror.com/mirrors/sqlite3
utf_8_validate_binary_host_mirror=https://npmmirror.com/mirrors/utf-8-validate/v{version}
uws_binary_host_mirror=https://npmmirror.com/mirrors/uws/v{version}
zmq_prebuilt_binary_host_mirror=https://npmmirror.com/mirrors/zmq-prebuilt/v{version}

Method 3: Temporary Use of Mirror

bash
# Temporarily use Taobao mirror to install packages
npm install --registry=https://registry.npmmirror.com @anthropic-ai/claude-code

# Or use npx
npx --registry=https://registry.npmmirror.com @anthropic-ai/claude-code --version

Use CNPM (Optional)

CNPM is an NPM client developed by Taobao team, using domestic mirror by default:

bash
# Install CNPM
npm install -g cnpm --registry=https://registry.npmmirror.com

# Use CNPM to install packages
cnpm install -g @anthropic-ai/claude-code

# Verify version
cnpm --version

Configure Acceleration for Yarn

If you use Yarn package manager:

bash
# Set Yarn mirror source
yarn config set registry https://registry.npmmirror.com

# Verify configuration
yarn config get registry

# Install Claude Code
yarn global add @anthropic-ai/claude-code

Configure Acceleration for PNPM

If you use PNPM package manager:

bash
# Set PNPM mirror source
pnpm config set registry https://registry.npmmirror.com

# Verify configuration
pnpm config get registry

# Install Claude Code
pnpm add -g @anthropic-ai/claude-code

Enterprise Configuration

For enterprise environments, you may need to configure proxy or private mirror:

Configure Proxy

bash
# HTTP proxy
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

# Authentication proxy
npm config set proxy http://username:[email protected]:8080
npm config set https-proxy http://username:[email protected]:8080

# SOCKS proxy
npm config set proxy socks://proxy.company.com:1080

Configure Private Mirror

bash
# Set private mirror
npm config set registry http://npm.company.com

# Configure scoped packages
npm config set @company:registry http://npm.company.com

Verification and Testing

Verify Configuration

bash
# View current configuration
npm config list

# View mirror source
npm config get registry

# View complete configuration
npm config ls -l | grep registry

Test Installation Speed

bash
# Clear cache
npm cache clean --force

# Test installation time
time npm install -g @anthropic-ai/claude-code

# View installation log
npm install -g @anthropic-ai/claude-code --verbose

Common Problem Solutions

Problem 1: Mirror source unavailable

Symptom:

npm ERR! network request to https://registry.npmmirror.com failed

Solution:

bash
# Switch to other mirror source
npm config set registry https://mirrors.cloud.tencent.com/npm

# Or restore official source
npm config set registry https://registry.npmjs.org

Problem 2: Certificate error

Symptom:

npm ERR! certificate verify failed

Solution:

bash
# Temporarily ignore SSL verification (not recommended)
npm config set strict-ssl false

# Or set certificate file
npm config set ca ""
npm config set cafile /path/to/certificate.pem

Problem 3: Proxy configuration conflict

Symptom: Installation failure or extremely slow speed

Solution:

bash
# Clear proxy configuration
npm config delete proxy
npm config delete https-proxy

# Reset mirror
npm config set registry https://registry.npmmirror.com

Problem 4: Configuration not taking effect

Solution:

bash
# Clear configuration cache
npm cache clean --force

# Delete node_modules and reinstall
rm -rf node_modules package-lock.json
npm install

# Check configuration file location
npm config get userconfig
npm config get globalconfig

Restore Default Configuration

If you need to restore to official mirror source:

bash
# Restore official mirror
npm config set registry https://registry.npmjs.org

# Delete custom configuration
npm config delete registry

# Or directly edit configuration file
npm config edit

Performance Optimization Suggestions

  1. Choose appropriate mirror source: Select the nearest mirror based on geographical location
  2. Regular configuration updates: Mirror source addresses may change
  3. Use cache: Make reasonable use of npm cache mechanism
  4. Network environment optimization: Install packages in stable network environment

After configuration is complete, the installation and update speed of Claude Code should be significantly improved!

Bring endless innovation and opportunities with AI
About
Features
Docs
Pricing
Contact us
Terms & Policies
Terms of Use
Privacy Policy
Specified Commercial Transactions Act