deno puppeteer 'chrome找不到'试图导入npm依赖项

ubof19bj  于 2023-01-09  发布在  其他
关注(0)|答案(1)|浏览(362)

我尝试在deno中使用node-html-to-image

import nodeHtmlToImage from "npm:node-html-to-image";

nodeHtmlToImage({
  output: './image.png',
  html: '<html><body>Hello world!</body></html>'
})
  .then(() => console.log('The image was created successfully!'))

deno run --allow-env --allow-read --allow-write that-file.ts导致此错误:

error: Uncaught Error: Unable to launch browser, error message: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (982053).
    at Cluster.<anonymous> (file:///Users/theonlygusti/Library/Caches/deno/npm/registry.npmjs.org/puppeteer-cluster/0.23.0/dist/Cluster.js:119:23)
    at Generator.throw (<anonymous>)
    at rejected (file:///Users/theonlygusti/Library/Caches/deno/npm/registry.npmjs.org/puppeteer-cluster/0.23.0/dist/Cluster.js:6:65)

如何使用Deno的node-html-to-image npm软件包?

h9vpoimq

h9vpoimq1#

基本上,这个问题在Could not find expected browser chrome locally中得到了解答。
Deno特有的部分是,NPM安装目录不同于通常的Node安装目录。
当您在Deno中使用npm specifier(例如import nodeHtmlToImage from "npm:node-html-to-image";)时,Node包将安装在deno缓存目录的一部分中:

  • 窗口:<user directory>/AppData/Local/deno/npm/registry.npmjs.org/
  • macOS操作系统:~/Library/Caches/deno/npm/registry.npmjs.org
  • Linux:$XDG_CACHE_HOME/deno/npm/registry.npmjs.org$HOME/.cache/deno/npm/registry.npmjs.org

特别是 puppet 人deno/npm/registry.npmjs.org/puppeteer/13.7.0
在错误消息中提到
运行npm install下载正确的Chromium版本(982053)
这意味着您应该在上面的Puppeteer目录中运行npm install,该目录包含一个名为install.js的文件。
这将把chromium包的正确版本安装到Puppeteer的.local-chromium目录下。
坏消息是(至少在Windows下),您可能会得到下一个错误,即
未捕获的错误:无法启动浏览器,错误消息:Windows仅支持ctrl-c(SIGINT)和ctrl-break(SIGBREAK)组合键。

相关问题