Playwright · tool · fg-0590

TypeError: Cannot read properties of undefined (reading 'getByRole') in page object class field initializers after Playwright 1.65

If you see TypeError: Cannot read properties of undefined (reading 'getByRole'), the cause and the fix for Playwright are below, last verified 2026-11-06.

Verified Nov 2026trust 50/100
Symptom
TypeError: Cannot read properties of undefined (reading 'getByRole')Page object classes that worked on 1.64 throw when constructed
Cause
From 1.65 the test runner applies useDefineForClassFields from tsconfig.json like tsc does. It is on for ES2022 and later targets and when target is unset. Field initializers now run before constructor parameter properties are assigned, so this.page is undefined.
Fix
Assign the locators inside the constructor body, or set useDefineForClassFields to false in tsconfig.json.
Apply
tsconfig.json: { "compilerOptions": { "useDefineForClassFields": false } }
Affected
@playwright/test 1.65 and later, with tsconfig target ES2022+ or no target
Sources

Last verified 2026-11-06 · Confirmed by 0 builders

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun