ネットワーク環境の制限により、NPM公式リポジトリから直接パッケージをダウンロードすると、以下の問題に遭遇する可能性があります:
国内ミラーソースを設定することで、インストール速度と成功率を大幅に向上させることができます。
以下の国内ミラーソースの使用を推奨します:
| ミラーソース | URL | メンテナンス | 推奨度 |
|---|---|---|---|
| Taobaoミラー | https://registry.npmmirror.com | Taobaoチーム | ⭐⭐⭐⭐⭐ |
| Tencentミラー | https://mirrors.cloud.tencent.com/npm | Tencent Cloud | ⭐⭐⭐⭐ |
| Huaweiミラー | https://mirrors.huaweicloud.com/repository/npm | Huawei Cloud | ⭐⭐⭐⭐ |
| USTCミラー | https://npmreg.proxy.ustclug.org | USTC LUG | ⭐⭐⭐ |
# Taobaoミラーを設定
npm config set registry https://registry.npmmirror.com
# 設定を確認
npm config get registry
# インストール速度をテスト
npm install -g @anthropic-ai/claude-code
# Tencentミラーを設定
npm config set registry https://mirrors.cloud.tencent.com/npm
# 設定を確認
npm config get registry
# Huaweiミラーを設定
npm config set registry https://mirrors.huaweicloud.com/repository/npm
# 設定を確認
npm config get registry
ユーザーのホームディレクトリまたはプロジェクトルートディレクトリに.npmrcファイルを作成:
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}
registry=https://registry.npmmirror.com
# 一時的にTaobaoミラーを使用してパッケージをインストール
npm install --registry=https://registry.npmmirror.com @anthropic-ai/claude-code
# またはnpxを使用
npx --registry=https://registry.npmmirror.com @anthropic-ai/claude-code --version
CNPMはTaobaoチームが開発したNPMクライアントで、デフォルトで国内ミラーを使用します:
# CNPMをインストール
npm install -g cnpm --registry=https://registry.npmmirror.com
# CNPMを使用してパッケージをインストール
cnpm install -g @anthropic-ai/claude-code
# バージョンを確認
cnpm --version
Yarnパッケージマネージャーを使用している場合:
# Yarnミラーソースを設定
yarn config set registry https://registry.npmmirror.com
# 設定を確認
yarn config get registry
# Claude Codeをインストール
yarn global add @anthropic-ai/claude-code
PNPMパッケージマネージャーを使用している場合:
# PNPMミラーソースを設定
pnpm config set registry https://registry.npmmirror.com
# 設定を確認
pnpm config get registry
# Claude Codeをインストール
pnpm add -g @anthropic-ai/claude-code
企業環境では、プロキシまたはプライベートミラーの設定が必要な場合があります:
# HTTPプロキシ
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
# 認証付きプロキシ
npm config set proxy http://username:[email protected]:8080
npm config set https-proxy http://username:[email protected]:8080
# SOCKSプロキシ
npm config set proxy socks://proxy.company.com:1080
# プライベートミラーを設定
npm config set registry http://npm.company.com
# スコープ付きパッケージの設定
npm config set @company:registry http://npm.company.com
# 現在の設定を表示
npm config list
# ミラーソースを表示
npm config get registry
# 完全な設定を表示
npm config ls -l | grep registry
# キャッシュをクリア
npm cache clean --force
# インストール時間をテスト
time npm install -g @anthropic-ai/claude-code
# インストールログを表示
npm install -g @anthropic-ai/claude-code --verbose
症状:
npm ERR! network request to https://registry.npmmirror.com failed
解決方法:
# 他のミラーソースに切り替え
npm config set registry https://mirrors.cloud.tencent.com/npm
# または公式ソースに戻す
npm config set registry https://registry.npmjs.org
症状:
npm ERR! certificate verify failed
解決方法:
# 一時的にSSL検証を無視(非推奨)
npm config set strict-ssl false
# または証明書ファイルを設定
npm config set ca ""
npm config set cafile /path/to/certificate.pem
症状: インストール失敗または極端に遅い速度
解決方法:
# プロキシ設定をクリア
npm config delete proxy
npm config delete https-proxy
# ミラーを再設定
npm config set registry https://registry.npmmirror.com
解決方法:
# 設定キャッシュをクリア
npm cache clean --force
# node_modulesを削除して再インストール
rm -rf node_modules package-lock.json
npm install
# 設定ファイルの場所を確認
npm config get userconfig
npm config get globalconfig
公式ミラーソースに戻す必要がある場合:
# 公式ミラーに復元
npm config set registry https://registry.npmjs.org
# カスタム設定を削除
npm config delete registry
# または設定ファイルを直接編集
npm config edit
設定完了後、Claude Codeのインストールと更新速度が大幅に向上するはずです!