一、判斷包來源是否正確
1. 檢查url
curl <registry_url>
2. 查看包是否存在
npm view <package_name> --registry=<registry_url>
二、局部registry配置步驟:
1. 全局配置
如果你希望對所有項目生效,可以將這行配置添加到全局.npmrc 文件中。全局 .npmrc文件通常位于以下路徑:
- Windows:
C:\Users\<YourUsername>\.npmrc
添加內容:
@sdp.nd:registry=http://registry.npm.sdp.nd
2. 項目級配置
如果你只希望對當前項目生效,可以在項目根目錄下創建或編輯 .npmrc 文件(與 package.json同級)。
添加內容:
@sdp.nd:registry=http://registry.npm.sdp.nd
3. 驗證配置
配置完成后,可以運行以下命令驗證:
npm config get @sdp.nd:registry
如果輸出為 http://registry.npm.sdp.nd
,說明配置成功。
4. 登錄私有倉庫(如果需要)
如果私有倉庫需要身份驗證,運行以下命令登錄:
npm login --registry=http://registry.npm.sdp.nd --scope=@sdp.nd
輸入用戶名、密碼和郵箱完成登錄。
三、安裝該SDK
執行以下命令,可以看到所有@sdp.nd的包從http://registry.npm.sdp.nd下載,其它包則從全局默認的registry下載
npm install --verbose
$ npm install --verbose
npm verb cli D:\node\node.exe D:\node\node_modules\npm\bin\npm-cli.js
npm info using npm@10.2.4
npm info using node@v20.11.0
npm verb title npm install
npm verb argv “install” “–loglevel” “verbose”
npm verb logfile logs-max:10 dir:C:\Users\Administrator\AppData\Local\npm-cache_logs\2025-03-29T12_55_13_064Z-
npm verb logfile C:\Users\Administrator\AppData\Local\npm-cache_logs\2025-03-29T12_55_13_064Z-debug-0.log
npm http fetch GET 200 http://registry.npm.sdp.nd/@sdp.nd%2fnd-uc-sdk 170ms (cache revalidated)
npm http fetch GET 200 http://registry.npm.sdp.nd/@sdp.nd%2frequest-adapter-waf 66ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/crypto-js 836ms (cache updated)
npm http fetch GET 200 https://registry.npmjs.org/nd-base64 849ms (cache updated)
npm http fetch GET 200 https://registry.npmjs.org/lodash 987ms (cache updated)
npm http fetch GET 200 https://registry.npmjs.org/nd-md5s 1054ms (cache updated)
npm http fetch GET 200 https://registry.npmjs.org/@babel%2fruntime 1061ms (cache updated)
npm http fetch GET 200 https://registry.npmjs.org/nd-datetime 1120ms (cache updated)
npm http fetch GET 200 https://registry.npmjs.org/nd-uri-parser 1322ms (cache updated)
npm http fetch GET 200 https://registry.npmjs.org/@gem-mine%2frequest 1441ms (cache updated)
npm http fetch GET 200 https://registry.npmjs.org/axios 259ms (cache updated)
npm http fetch GET 200 https://registry.npmjs.org/regenerator-runtime 275ms (cache updated)
npm http fetch GET 200 https://registry.npmjs.org/@gem-mine%2frequest-adapter-xhr 546ms (cache updated)
npm http fetch GET 200 https://registry.npmjs.org/follow-redirects 263ms (cache updated)
npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/advisories/bulk 295ms
npm http fetch GET 200 http://registry.npm.sdp.nd/@sdp.nd/nd-uc-sdk/download/@sdp.nd/nd-uc-sdk-1.9.34.tgz 346ms (cache miss)
一般上述命令能夠安裝成功,如果不能,也可以下載包的.tgz文件到本地,運行如下安裝命令即可:
npm install ./*.tgz --save