The fix has been merged: #27846.
How to resolve TypeScript paths in Playwright tests.
An issue for this already exists the Playwright repo: #27933.
Currently Playwright won't resolve paths
in tsconfig.json
unless baseURL
is set explicitly.
Example:
{
"compilerOptions": {
"baseURL": "."
}
}
This should not be required according to the TypeScript docs on the paths
option.
Clone this repro repo and and install the dependencies:
git clone git@github.com:valler/playwright-ts-paths-repro.git
cd playwright-ts-paths-repro
npm i
Alternatively, start a GitHub Codespace.
Run the test:
npm t
This fails with an error containing:
Error: Cannot find package '~src'
Set the baseURL
in tests/tsconfig.json to "."
. You can uncomment the prepared line.
Run the test:
npm t
The test should pass.