1002: [FJOI2007]轮状病毒

本文介绍了一种计算不同轮状病毒数量的方法,利用特定的递推公式进行编程实现,并给出了具体的代码示例。

Description

给定n(N<=100),编程计算有多少个不同的n轮状病毒。

Input

第一行有1个正整数n。

Output

将编程计算出的不同的n轮状病毒数输出

Sample Input

3

Sample Output

16


基尔霍夫矩阵(我也不知道是什么)推出f[i]=(f[i-1]*3-f[i-2]+2)

给定一个有n个顶点的图G,它的拉普拉斯矩阵
定义为:
L=D-A
其中D为图的度矩阵,A为图的 邻接矩阵。度矩阵在有向图中,只需要考虑出度或者入度中的一个。经过计算可以得
1、若i
 =j,则
为顶点
的度。
2、若i≠ j,但顶点
和顶点
相邻,则
3、其它情况
也可以将这三种值通过除以
进行标准化。

code:

#include<iostream>
#include<cstdio>
using namespace std ;
struct data {
       int a [ 101 ] , len ;
       } ;
int n ;
data mul ( data a , int k )
{
     for ( int i = 1 ; i <= a . len ; i ++ )
             a . a [ i ] *= k ;
     for ( int i = 1 ; i <= a . len ; i ++ )
     {
             a . a [ i + 1 ] += a . a [ i ] / 10 ;
             a . a [ i ] %= 10 ;
             }
     if ( a . a [ a . len + 1 ] != 0 ) a . len ++ ;
     return a ;
}
data sub ( data a , data b )
{
     a . a [ 1 ] += 2 ;
     int j = 1 ;
     while ( a . a [ j ] >= 10 ) { a . a [ j ] %= 10 ; a . a [ j + 1 ] ++ ; j ++ ; }
     for ( int i = 1 ; i <= a . len ; i ++ )
     {
           a . a [ i ] -= b . a [ i ] ;
           if ( a . a [ i ] < 0 ) { a . a [ i ] += 10 ; a . a [ i + 1 ] -- ; }
     }
     while ( a . a [ a . len ] == 0 ) a . len -- ;
     return a ;
}
int main ( )
{
     data f [ 101 ] ; f [ 1 ] . a [ 1 ] = 1 ; f [ 2 ] . a [ 1 ] = 5 ;
     f [ 1 ] . len = f [ 2 ] . len = 1 ;
     scanf ( "%d" , &n ) ;
     for ( int i = 3 ; i <= n ; i ++ )
             f [ i ] = sub ( mul ( f [ i - 1 ] , 3 ) , f [ i - 2 ] ) ;
     for ( int i = f [ n ] . len ; i > 0 ; i -- )
       printf ( "%d" , f [ n ] . a [ i ] ) ;
     return 0 ;
}

npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for @hapi/hoek@8.5.1 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/@hapi%2fhoek failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for @hapi/joi@15.1.1 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/@hapi%2fjoi failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for @hapi/topo@3.1.6 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/@hapi%2ftopo failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for postcss@7.0.39 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/postcss failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for @intlify/core-base@9.14.5 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/@intlify%2fcore-base failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for picocolors@0.2.1 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/picocolors failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for @intlify/shared@9.14.5 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/@intlify%2fshared failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for @intlify/message-compiler@9.14.5 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/@intlify%2fmessage-compiler failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for @isaacs/cliui@8.0.2 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/@isaacs%2fcliui failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for ansi-regex@6.2.2 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/ansi-regex failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for emoji-regex@9.2.2 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/emoji-regex failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for ansi-styles@6.2.3 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/ansi-styles failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for string-width@5.1.2 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/string-width failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for strip-ansi@7.1.2 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/strip-ansi failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for wrap-ansi@8.1.0 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/wrap-ansi failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for @jridgewell/gen-mapping@0.3.13 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/@jridgewell%2fgen-mapping failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for @jridgewell/sourcemap-codec@1.5.5 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/@jridgewell%2fsourcemap-codec failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for @jridgewell/resolve-uri@3.1.2 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/@jridgewell%2fresolve-uri failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for @jridgewell/trace-mapping@0.3.31 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/@jridgewell%2ftrace-mapping failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'system' npm warn old lockfile } npm warn old lockfile Could not fetch metadata for @jridgewell/remapping@2.3.5 FetchError: request to https://cmc.centralrepo.rnd.huawei.com/npm/@jridgewell%2fremapping failed, reason: unable to verify the first certificate npm warn old lockfile at ClientRequest.<anonymous> (C:\Users\x60102926\AppData\Local\nvm\v22.19.0\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14) npm warn old lockfile at ClientRequest.emit (node:events:519:28) npm warn old lockfile at emitErrorEvent (node:_http_client:105:11) npm warn old lockfile at _destroy (node:_http_client:898:9) npm warn old lockfile at onSocketNT (node:_http_client:918:5) npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm warn old lockfile code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', npm warn old lockfile type: 'syst
最新发布
12-12
你遇到的错误: ``` UNABLE_TO_VERIFY_LEAF_SIGNATURE ``` 以及请求失败指向了华为内部仓库: ``` https://cmc.centralrepo.rnd.huawei.com/npm/... ``` 这表明你的 npm 配置使用的是 **华为公司内网私有镜像源**,而你现在的问题是:**Node.js 无法验证该 HTTPS 服务器证书的有效性(通常是自签名证书)**。 --- ## 🔍 错误原因分析 - 公司私有 NPM 仓库(如 `cmc.centralrepo.rnd.huawei.com`)通常使用 **企业内网 CA 签发的 SSL 证书**。 - 你的操作系统或 Node.js 没有信任这个 CA 证书 → 导致 `UNABLE_TO_VERIFY_LEAF_SIGNATURE`。 - 这不是网络不通,而是 TLS 握手失败 —— 安全机制阻止了请求。 --- ## ✅ 解决方案(按推荐顺序) ### ✅ 方法一:安装企业根证书(最安全、推荐) > 💡 联系你们公司的 IT 或前端基建团队获取“企业根证书”(一般是 `.crt` 或 `.pem` 文件)。 #### 步骤如下: 1. **获取企业 CA 证书文件** 比如叫 `huawei-ca.crt` 2. **配置 npm 使用该证书** ```bash npm config set cafile "C:\path\to\huawei-ca.crt" ``` 示例: ```bash npm config set cafile "C:\certs\huawei-ca.crt" ``` ✅ 这样 npm 就会信任你们公司签发的所有证书。 3. (可选)验证是否生效 ```bash npm config get cafile ``` --- ### ✅ 方法二:临时关闭 SSL 验证(仅测试用!不推荐生产) 如果你只是想快速验证是否是证书问题,可以临时禁用: ```bash npm config set strict-ssl false ``` ⚠️ 警告:这样做会让所有 HTTPS 请求不再校验证书,存在中间人攻击风险! > ❌ 不建议长期使用,尤其不要在正式开发中开启。 恢复命令: ```bash npm config set strict-ssl true ``` --- ### ✅ 方法三:设置 NODE_EXTRA_CA_CERTS 环境变量(高级用法) 适用于 Electron、CI 环境等场景。 ```bash set NODE_EXTRA_CA_CERTS=C:\certs\huawei-ca.crt ``` 然后运行 npm 命令: ```bash npm install ``` 这样 Node.js 会在默认 CA 基础上额外信任你提供的证书。 --- ### ✅ 方法四:检查代理设置(如有使用) 有些公司需要配合代理才能访问内部仓库: ```bash npm config get proxy npm config get https-proxy ``` 如果应该设置但没设,可以: ```bash npm config set proxy http://proxy.yourcompany.com:8080 npm config set https-proxy http://proxy.yourcompany.com:8080 ``` > 具体地址请咨询 IT 部门。 --- ## 🧪 如何确认问题是出在证书上? 你可以手动测试连接: ```bash curl -v https://cmc.centralrepo.rnd.huawei.com/npm/ ``` 或者用浏览器打开这个链接: 👉 [https://cmc.centralrepo.rnd.huawei.com/npm/](https://cmc.centralrepo.rnd.huawei.com/npm/) - 如果浏览器提示“不安全”、“证书不受信任”,那就是证书问题。 - 正常情况下你应该看到一个 JSON 响应(可能是 forbidden,但不能是证书错误)。 --- ## 📌 总结与建议 | 方案 | 是否推荐 | 说明 | |------|--------|------| | ✅ `cafile` 设置企业 CA 证书 | ⭐⭐⭐⭐⭐ | 最安全、最规范 | | ⚠️ `strict-ssl=false` | ⚠️ 仅临时 | 快速排查可用,禁止提交到项目 | | ✅ `NODE_EXTRA_CA_CERTS` | ⭐⭐⭐⭐ | 适合自动化脚本和 CI | | 🔁 检查代理和网络 | 必须做 | 确保能连通内网服务 | --- 上述代码通过设置 `npm config set cafile` 来指定企业级 CA 证书路径,使 Node.js 能够信任公司私有 NPM 仓库的 HTTPS 证书,从而解决 `UNABLE_TO_VERIFY_LEAF_SIGNATURE` 错误。这是企业内网环境下安全合规的做法。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值