lucacasonato / deno-puppeteer

A port of puppeteer running on Deno
https://deno.land/x/puppeteer
MIT License
454 stars 44 forks source link

`Deno.core.runMicrotasks()` is not supported in this environment #74

Closed andrewbrey closed 1 year ago

andrewbrey commented 1 year ago

First of all, thank you very much for your work on Deno, its ecosystem, in the TC39 as a deligate (Response.json wooo!), with Fresh, and in general in open source. It's extremely appreciated and you're doing a great job!

This evening, after upgrading from deno v1.29.4 to deno v1.30.0 I began to see the following error when I ran code which imports this module:

error: Uncaught Error: Deno.core.runMicrotasks() is not supported in this environment
      throw new Error(
            ^
    at Object.runMicrotasks (https://deno.land/std@0.170.0/node/_core.ts:22:13)
    at processTicksAndRejections (https://deno.land/std@0.170.0/node/_next_tick.ts:62:10)
    at https://deno.land/std@0.170.0/node/process.ts:375:7
    at innerInvokeEventListeners (deno:ext/web/02_event.js:776:9)
    at invokeEventListeners (deno:ext/web/02_event.js:816:7)
    at dispatch (deno:ext/web/02_event.js:685:11)
    at dispatchEvent (deno:ext/web/02_event.js:1066:14)
    at [deno:cli/worker.rs:90:39]:1:1

Here is all that is needed to reproduce this error:

// ./mod.ts

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

if (import.meta.main) {
  console.log(puppeteer);
}

deno run --allow-env ./mod.ts

For context, here is information about my environment:

Deno Version: 1.30.0
deno --version
deno 1.30.0 (release, x86_64-unknown-linux-gnu)
v8 10.9.194.5
typescript 4.9.4

OS: Pop!_OS 22.04 LTS x86_64 (Linux)

Also, I looked into this error a little (at the referenced line at the top of the stack trace https://deno.land/std@0.170.0/node/_core.ts:22:13 as well as the analogous code in the latest version of stdlib https://deno.land/std@0.174.0/node/_core.ts?source#L26), which prompted me to go into the repl and just see what I get when I check the availability of that internal Deno-core set of APIs, and found the following:

> Deno?.[Deno.internal]?.core.runMicrotasks.toString()
"() => ops.op_run_microtasks()"
> Deno?.core?.runMicrotasks
undefined

so, apparently between deno v1.29.4 and deno v1.30.0, something was moved out of Deno.core and into Deno[Deno.internal].core (if I'm reading this right). I did not check if this was just the fruition of a deprecation, but I wouldn't be surprised to learn that it was given that we just crossed a new minor.

It's possible that all that's needed to address this is to bump the versions of the stdlib being used by deno-puppeteer but I wanted to surface this error in case there's something deeper going on.


I looked around for alternate puppeteer modules for Deno, and found that this one, https://deno.land/x/deno_puppeteer@0.13.0, is able to run a simple script just fine for me:

e.g.

// ./second-mod.ts

import { puppeteer } from "https://deno.land/x/deno_puppeteer@0.13.0/mod.ts";

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://example.com");
await page.screenshot({ path: "example.png" });

await browser.close();

deno run -A ./second-mod.ts

but there are no others which worked when I tried for various reasons (most seem to be due to things being out of date).

Also weird, is that the GitHub repo associated with https://deno.land/x/deno_puppeteer@0.13.0 is 404'ing , and in fact, so is that entire user account...weird :grimacing:

andrewbrey commented 1 year ago

This morning, I decided to look into this more and forked the repository so that I could run the actions once I poked around with some changes. To my surprise, when I ran the ci.yml workflow, everything came out just fine:

image

notice in the screenshot that the action used deno 1.30.0

this lead me to think that the issue was something stale in my local DENO_DIR caches, so I nuked all of my deno caches and let everything re-download/re-cache, and now everything is working as expected!

So, the good news is that I can close this issue I believe because I don't think this is an issue with deno-puppeteer . I do not know what things I could have done differently to clue me into the need to nuke my cache sooner, but going forward, I think it'll be a standard triage step for me with Deno.

Leaving all this information here for posterity, but I'll go ahead an close this issue - cheers!

jespertheend commented 1 year ago

Thanks! I ran into the same issue. For anyone else: You can find the location of your deno caches folder by running deno info. echo $DENO_DIR didn't work for me.