Playwright 1.65 now follows useDefineForClassFields. If your page object builds locators in class fields, they run before this.page exists. Three fixes, and which one I'd pick.

You upgrade Playwright. Nothing else changes. Half your suite goes red with this:

TypeError: Cannot read properties of undefined (reading 'getByLabel') 

The tests didn't change. The app didn't change. So what did?

The pattern that breaks

If your page objects look like this, this post is for you:

import { Page } from '@playwright/test'; export class LoginPage { readonly email = this.page.getByLabel('Email'); readonly password = this.page.getByLabel('Password'); readonly submit = this.page.getByRole('button', { name: 'Sign in' }); constructor(private readonly page: Page) {} } 

It's short and tidy, and it's everywhere. It worked fine up to Playwright 1.64.

What changed in 1.65

From the 1.65.0 release notes: TypeScript class fields now follow useDefineForClassFields from your tsconfig.json, the same way tsc does.

That setting is on by default when your target is ES2022 or later, and also when target isn't set at all. So most projects get it without touching anything.

With it on, the order inside the class changes:

  1. Class fields are set up first (email, password, submit)
  2. Then the constructor runs and assigns page

So when email tries to read this.page, page doesn't exist yet. Hence undefined, hence the TypeError.

Before 1.65, Playwright's own transpiling didn't follow that setting, so page happened to be there in time. The code was always relying on the old order. 1.65 just stopped hiding it.

Fix 1: build the locators in the constructor (the one I'd pick)

import { Page, Locator } from '@playwright/test'; export class LoginPage { readonly email: Locator; readonly password: Locator; readonly submit: Locator; constructor(private readonly page: Page) { this.email = page.getByLabel('Email'); this.password = page.getByLabel('Password'); this.submit = page.getByRole('button', { name: 'Sign in' }); } } 

A few more lines, but the order is explicit. It works with any tsconfig, any target, any tool. This is also the shape the Playwright docs use for page objects.

Fix 2: use getters

export class LoginPage { constructor(private readonly page: Page) {} get email() { return this.page.getByLabel('Email'); } get password() { return this.page.getByLabel('Password'); } get submit() { return this.page.getByRole('button', { name: 'Sign in' }); } } 

A getter only runs when you use it, and by then page is set. Locators are lazy anyway, so creating a fresh one on each access costs nothing that matters. Nice if you like the one-line style.

Fix 3: turn the setting off

{ "compilerOptions": { "useDefineForClassFields": false } } 

This gets you green again in one line. But it changes how class fields behave across your whole project, not just in page objects. I'd use it to unblock a release, then move to Fix 1 or 2.

Why it can pass on your machine and fail in CI

This one fits my "Fails only in CI" series.

If your package.json says "@playwright/test": "^1.64.0", and CI installs without respecting the lockfile, CI can pick up 1.65 while your laptop is still on 1.64. Same code, green locally, red in CI. That's the dependency drift readers described in Part 2.

Use npm ci in CI, commit the lockfile, and upgrade Playwright on purpose, not by accident.

Quick checklist before you upgrade

  • Search your page objects for class fields that use this.page (for example = this.page.)
  • Check your tsconfig.json target. ES2022 or later, or no target at all, means the new behaviour applies
  • Pick Fix 1 or Fix 2 and change them in one go
  • Upgrade in a branch and run the full suite before merging

What AI tools get wrong here

If you paste the TypeError into an AI assistant without context, you can get "add a null check" or "make sure page is defined" as the first suggestion. That turns the TypeError into a quieter failure later. The real fix is about order, not null checks. Give it the class and the Playwright version, and it gets there much faster.

Has 1.65 broken anything else in your suite? Drop it in the comments.

I'm building Locator League, browser-based Playwright challenges where you write the test and it runs for real. The Foundation track is free with an account.