Skip to content

prelude-in-page ​

A prelude value used inside a function that Playwright or Puppeteer runs in the browser page: page.evaluate(fn), evaluateHandle, addInitScript(fn), waitForFunction(fn), $eval(selector, fn) and $$eval(selector, fn). Reported in files with the prelude on.

Why: the transform makes prelude names work by importing them into the module. The function given to page.evaluate is not run in the module: it is turned into text and run in the page, where those imports don't exist. err, isErr, unsafe or q there fail with ReferenceError: err is not defined, in the browser, when the test runs. Nothing else says so: the editor and tsc see the prelude's global declarations.

✕ Rejectedprelude-in-page
ts
declare const page: { evaluate<T>(fn: () => T): Promise<T> };

export async function cartSize(): Promise<number> {
  return page.evaluate(() => {
    const items = unsafe(() => JSON.parse(localStorage.getItem("cart") ?? "[]"));
    return isErr(items) ? 0 : 1;
  });
}

✅ Accepted: read plain data in the page, do the rest in the test

✓ Accepted0 diagnostics
ts
declare const page: { evaluate<T>(fn: () => T): Promise<T> };

export async function cartSize(): Promise<number> {
  const raw = await page.evaluate(() => localStorage.getItem("cart") ?? "[]");
  const items = unsafe(() => JSON.parse(raw));
  return isErr(items) ? 0 : 1;
}

Values the page needs go in as an argument: page.evaluate((n) => n * 2, count). Your own imports have the same problem in such a function; the rule names the prelude's, because they don't look imported.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra