I maintain a number of Playwright tests for work and recently ran into a frustrating issue. I set up my new desktop recently and everything was running great but I was having issues getting intellisense to work for my Playwright stuff. At the top of all of my tests I was getting the dreaded:
Cannot find module '@playwright/test' or its corresponding type declarations.ts(2307)
error when hovering over:
import { expect, test } from '@playwright/test';
I did a bunch of searches online that mention making sure Playwright is installed properly using npx playwright install
. In my case I knew everything was set up and we use yarn workspaces for our project anyway. Well fortunately all of this was working on my Thinkpad so I started trying to compare everything. I had the Playwright extension installed already. I use VSCodium instead of VSCode but that doesn’t matter in this case. Then I wondered if maybe, just maybe it was a TypeScript issue so I looked at the version running on my Thinkpad. It was an older version than what was running on my desktop. I switched it on my desktop to use the workspace version and voila, everything started working!
In case you are curious, the version I was having problems with was TypeScript 5.7.2
and the version that works for me is TypeScript 5.5.4-sdk
.
If you aren’t sure how to change this setting, open a TypeScript file in your editor and look for TypeScript
in the lower right hand toolbar. Their should be a pair of {}
next to it. Clicking the {}
will open the menu.
This is the same for VSCode as well.