(笔记)RequestError: Hostname/IP does not match certificate‘s altnames: Host: .解决方法

时间:2025-04-08 13:13:47
(base) ➜  camera-app pnpm install --save-dev electron


Packages: +75
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 75, reused 75, downloaded 0, added 0, done
node_modules/.pnpm/electron@31.0.0/node_modules/electron: Running postinstall script, failed in 422ms
.../node_modules/electron postinstall$ node 
│ RequestError: Hostname/IP does not match certificate's altnames: Host: . is not in the cert's altnames: DNS:*., DN…
│     at ClientRequest.<anonymous> (/Users/simley/ElectronProjects/camera-app/node_modules/.pnpm/got@11.8.6/node_modules/got/dist/source/c…
│     at  (node:events:634:26)
│     at  (node:events:531:35)
│     at  (/Users/simley/ElectronProjects/camera-app/node_modules/.pnpm/@szmarczak+http-timer@4.0.6/node_modules/@szmarczak/htt…
│     at  (node:_http_client:500:9)
│     at  (node:events:519:28)
│     at emitErrorNT (node:internal/streams/destroy:169:8)
│     at emitErrorCloseNT (node:internal/streams/destroy:128:3)
│     at  (node:internal/process/task_queues:82:21)
│     at  (node:tls:337:12)
│     at  (node:_tls_wrap:1684:27)
│     at  (node:events:519:28)
│     at TLSSocket._finishInit (node:_tls_wrap:1085:8)
│     at  (node:_tls_wrap:871:12)
└─ Failed in 423ms at /Users/simley/ElectronProjects/camera-app/node_modules/.pnpm/electron@31.0.0/node_modules/electron
 ELIFECYCLE  Command failed with exit code 1.

输入了下面的命令来修改electron_mirror,但是没生效

pnpm config set electron_mirror /mirrors/electron/

然后输入`npm config set electron_mirror /mirrors/electron/`

(base) ➜  camera-app npm config set electron_mirror /mirrors/electron/
npm ERR! `electron_mirror` is not a valid npm option

npm ERR! A complete log of this run can be found in: /Users/simley/.npm/_logs/2024-06-12T01_14_31_674Z

但是报错了

最后输入`npm config ls`

找到npm的配置文件 /Users/simley/.npmrc

(base) ➜  camera-app npm config ls

; "user" config from /Users/simley/.npmrc

electron_mirror = "/mirrors/electron/"
https-proxy = "http://127.0.0.1:7890/"
proxy = "http://127.0.0.1:7890/"
registry = ""
strict-ssl = false

输入vim ~/.npmrc

最后将/mirrors/electron/ 改成 /mirrors/electron/

electron_mirror=/mirrors/electron/
https-proxy=http://127.0.0.1:7890/
proxy=http://127.0.0.1:7890/
registry=
strict-ssl=false

:wq保存就OK了