Home > Enterprise >  deno puppeteer 'chrome not found' trying to import npm dependency
deno puppeteer 'chrome not found' trying to import npm dependency

Time:01-08

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?

CodePudding user response:

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 installtions.

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:

  • Windows: <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 or $HOME/.cache/deno/npm/registry.npmjs.org

and specifically for Puppeteer: deno/npm/registry.npmjs.org/puppeteer/13.7.0

Run npm install in puppeteer's directory

This will download a chromium package which goes into the above mentioned 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).

  • Related