puppeteer下载失败问题
使用的淘宝镜像,但执行命令npm i puppeteer
之后,报错:
npm ERR! code 1
npm ERR! path E:\项目-临时\test_install_puppeteer\node_modules\puppeteer
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node install.mjs
npm ERR! PUPPETEER_DOWNLOAD_HOST is deprecated. Use PUPPETEER_DOWNLOAD_BASE_URL instead.
npm ERR! ERROR: Failed to set up Chrome r119.0.6045.105! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.
npm ERR! Error: Download failed: server returned code 404. URL: https://cdn.npmmirror.com/binaries/119.0.6045.105/win64/chrome-win64.zip
npm ERR! at file:///E:/%E9%A1%B9%E7%9B%AE-%E4%B8%B4%E6%97%B6/test_install_puppeteer/node_modules/@puppeteer/browsers/lib/esm/httpUtil.js:74:31
npm ERR! at ClientRequest.requestCallback (file:///E:/%E9%A1%B9%E7%9B%AE-%E4%B8%B4%E6%97%B6/test_install_puppeteer/node_modules/@puppeteer/browsers/lib/esm/httpUtil.js:52:13)
npm ERR! at Object.onceWrapper (node:events:629:26)
npm ERR! at ClientRequest.emit (node:events:514:28)
npm ERR! at HTTPParser.parserOnIncomingClient (node:_http_client:693:27)
npm ERR! at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
npm ERR! at TLSSocket.socketOnData (node:_http_client:535:22)
npm ERR! at TLSSocket.emit (node:events:514:28)
npm ERR! at addChunk (node:internal/streams/readable:545:12)
npm ERR! at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)
看到一个帖子说的是
点击帖子
2023 update:
npm config set registry https://registry.npmmirror.com
npm set registry https://mirrors.cloud.tencent.com/npm/
对于Puppeteer20.1以上的版本,可以通过以下方式使用国产镜像源:
puppeteer-download-base-url="https://cdn.npmmirror.com/binaries/chrome-for-testing"
19以下版本还是原来的方式:
puppeteer-download-host="https://cdn.npmmirror.com/binaries"
解决办法:
- 配置下载镜像淘宝或腾讯的;可以使用
nrm
切换(方便) - 在根目录下创建一个文件
.npmrc
,内容填充你对应的版本代码
# 19以下版本
PUPPETEER_DOWNLOAD_HOST = https://cdn.npmmirror.com/binaries
# 20以上的版本
PUPPETEER_DOWNLOAD_BASE_URL = https://cdn.npmmirror.com/binaries/chrome-for-testing
3. 删除node_modules后重新执行命令npm i puppeteer