I'm trying to use node-html-to-image
in deno:
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
causes this error:
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)
How can I use the node-html-to-image
npm package from Deno?
Basically, this is answered in Could not find expected browser chrome locally.
The Deno-specific part is, that the NPM installation directory is different from the usual Node installations.
When you use the npm specifier in Deno, e.g. import nodeHtmlToImage from "npm:node-html-to-image";
, the Node packages will be installed in a part of the deno caches directory:
<user directory>/AppData/Local/deno/npm/registry.npmjs.org/
~/Library/Caches/deno/npm/registry.npmjs.org
$XDG_CACHE_HOME/deno/npm/registry.npmjs.org
or $HOME/.cache/deno/npm/registry.npmjs.org
and specifically for Puppeteer:
deno/npm/registry.npmjs.org/puppeteer/13.7.0
In the error message it's mentioned to
Run
npm install
to download the correct Chromium revision (982053)
That means you should run npm install
in the above Puppeteer's directory, which contains a file named install.js.
This will install the correct revision of the chromium package into the Puppeteer's directory under .local-chromium
.
The bad news is (at least under Windows), that you'll probably get the next error, which is
Uncaught Error: Unable to launch browser, error message: Windows only supports ctrl-c (SIGINT) and ctrl-break (SIGBREAK).