Skip to content

🐛 BUG: ReferenceError: __name is not defined in await page.evaluate(async () => {...} #7107

@L480

Description

@L480

Which Cloudflare product(s) does this pertain to?

Workers Runtime, Wrangler

What version(s) of the tool(s) are you using?

3.83.0

What version of Node are you using?

20.18.0

What operating system and version are you using?

Ubuntu 22.04.5 LTS

Describe the Bug

Observed behavior

ReferenceError: __name is not defined worker exception after wrangler deploy.
I'm having this error inside of await page.evaluate(async () => {...} code for puppeteer. It adds __name to my arrow function for some reason. I think this is likely due to minifyIdentifiers in esbuild. This behavior appeared in wrangler 3.83.0. However, it is working in wrangler 3.78.12.

Expected behavior

No minified function names in await page.evaluate(async () => {...}.

Steps to reproduce

Please provide the following:

  • A minimal working subset of your worker code
import { Page } from '@cloudflare/puppeteer'

export async function scrapeDetails(page: Page) {
    await page.goto('https://example.com')
    const data = await page.evaluate(() => {
        function toNumber(str: string | undefined): number | undefined {
            const num = typeof str === 'string' ? str.replaceAll('.', '').replaceAll(',', '.').match(/[+-]?([0-9]*[.])?[0-9]+/) : false
            if (num) {
                return Number(num[0])
            } else {
                return undefined
            }
        }

        const table = document.getElementById('test')
        let metadata = {} as { test: number | undefined }
        if (table) {
            for (let item of table.getElementsByTagName('li')) {
                const data = item.innerText.split('\n')
                switch (data[0]) {
                    case 'test':
                        metadata.test = toNumber(data[1])
                        break
                }
            }
        }
        return metadata
    })
    return data
}

Get's bundled into:

async function scrapeDetails(page) {
  await page.goto("https://example.com");
  const data = await page.evaluate(() => {
    function toNumber(str) {
      const num = typeof str === "string" ? str.replaceAll(".", "").replaceAll(",", ".").match(/[+-]?([0-9]*[.])?[0-9]+/) : false;
      if (num) {
        return Number(num[0]);
      } else {
        return void 0;
      }
    }
    __name(toNumber, "toNumber"); // <== This is the issue
    const table = document.getElementById("test");
    let metadata = {};
    if (table) {
      for (let item of table.getElementsByTagName("li")) {
        const data2 = item.innerText.split("\n");
        switch (data2[0]) {
          case "test":
            metadata.test = toNumber(data2[1]);
            break;
        }
      }
    }
    return metadata;
  });
  return data;
}
  • A minimal working subset of your wrangler.toml
name = "my-app"
main = "src/index.ts"
compatibility_date = "2024-09-02"
logpush = false
tail_consumers = [{service = "law-ingestion"}]
compatibility_flags = [ "nodejs_compat" ]

[triggers]
crons = ["*/15 * * * *"]

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething that isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions