我尝试在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软件包?
1条答案
按热度按时间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/
~/Library/Caches/deno/npm/registry.npmjs.org
$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)组合键。