ratson / puppeteer_plus

Deno port of puppeteer base on latest TypeScript source.
https://deno.land/x/puppeteer_plus
MIT License
20 stars 4 forks source link

`error: Uncaught (in promise) TypeError: Relative import path "stream" not prefixed with / or ./ or ../` #2

Closed jerrygreen closed 1 year ago

jerrygreen commented 2 years ago

When I try to run deno run -A --unstable html2pdf.ts, I get this error:

error: Uncaught (in promise) TypeError: Relative import path "stream" not prefixed with / or ./ or ../
    at [https://deno.land/x/puppeteer_plus@0.14.0/vendor/puppeteer/src/common/util.ts:487:35

  const {Readable} = await import('stream');
                     ^
    at async getReadableFromProtocolStream (https://deno.land/x/puppeteer_plus@0.14.0/vendor/puppeteer/src/common/util.ts:487:22)
    at async Page.pdf (https://deno.land/x/puppeteer_plus@0.14.0/vendor/puppeteer/src/common/Page.ts:3055:22)
    at async file:///home/ubuntu/Projects/html-to-pdf/html2pdf.ts:14:1

html2pdf.ts:

import puppeteer from "https://deno.land/x/puppeteer_plus@0.14.0/mod.ts";

const browser = await puppeteer.launch({
  headless: true,
  args: ['--no-sandbox', '--disable-setuid-sandbox'],
})

const page = await browser.newPage()

await page.goto('https://example.com', {
  waitUntil: 'networkidle2',
})

await page.pdf({ path: 'file.pdf' })

await browser.close()

Deno.version:

{
   "deno": "1.24.3",
   "v8":" 10.4.132.20",
   "typescript": "4.7.4"
}

I'm not sure how often this problem might be in the puppeteer, but it seems Deno require a fix for this code:

https://github.com/ratson/puppeteer_plus/blob/68223f46614434d2f089068e07c5b9ace05e52ba/vendor/puppeteer/src/common/util.ts#L487

Maybe something like await import('./stream'); will do, but not sure in how many places.

Also, isn't that Deno requires file extensions in the import path, like .ts?