Problems with basic Puppeteer setup

Hi there!
I've setup a basic Worker project using npm create cloudflare@latest.

After that, I installed @cloudflare/puppeteer, updates my wrangler.jsonc to include the binding, and set the required compatibility flags.

I followed the documentation (https://developers.cloudflare.com/browser-rendering/platform/puppeteer/) and copied the example code into my own project:

import puppeteer from '@cloudflare/puppeteer';

interface Env {
    CRAWLER_BROWSER: Fetcher;
}

export default {
    async fetch(request, env): Promise<Response> {
        const browser = await puppeteer.launch(env.CRAWLER_BROWSER);
        const page = await browser.newPage();
        await page.goto('https://example.com');
        const metrics = await page.metrics();
        await browser.close();
        return Response.json(metrics);
    },
} satisfies ExportedHandler<Env>;


When I test locally using npm run dev, I get the following error:

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/xxxx/xxxx/node_modules/youch/build/index.js from /home/xxxx/xxxx/node_modules/miniflare/dist/src/index.js not supported.
Instead change the require of /home/xxxx/xxxx/node_modules/youch/build/index.js in /home/xxxx/xxxx/node_modules/miniflare/dist/src/index.js to a dynamic import() which is available in all CommonJS modules.
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at handlePrettyErrorRequest

Running remotely works fine, the issue only happens when testing locally.
It feels like I’m missing something in the setup, but I can’t figure out what. Has anyone run into this before, or know how to resolve it?

Thanks!
Was this page helpful?