- 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