[BUG] Playwright Stack trace shows wrong line number for failure if importing certain packages
System info
- Playwright Version: 1.41
- Operating System: Windows 11
- Browser: All
- Other info: Node v16.20.2
Source code
example.spec.ts
import { test } from "@playwright/test";
require("appium-windows-driver");
test("Basic Test", () => {
throw new Error("Will fail");
});
Package.json
{
"name": "playwright_sandbox",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.41.1",
"appium-windows-driver": "1.19.1"
}
}
Steps
- [Run the test]
Expected
I would expect line 8 to be the line we have a failure
Actual
Looks like the whitespace confuses playwright with the import? we have it on line 6
Note this is a wacky repro but it's the smallest I could do that is portable, we don't actually have tests like this :)
Commenting out the require shows "Expected" results again :
Removing all new lines and we still have the weird line count issue :
Hmm, wasn't able to reproduce it on linux with node 18 or 16. This is the project that I used https://github.com/yury-s/bug-29157. Let me try on Windows too.
I can't either, I wonder if its due to me making this repro as small as possible but Playwright still using the same compilation cache?
There is a chance that something got stuck somewhere (node_modules?). Does it reproduce with the original project on a fresh checkout?
I can repro.
The wrong source-map-support package gets picked up:
https://github.com/appium/appium-windows-driver/blob/53f9603cb8d8a54fc39a6dfcc5b7b239cd9f2afa/package.json#L64
They also internally do a lot of require("source-map-support/register"). It also depends on the asyncbox package, which does the same hence its not working.
Workaround: Put require('source-map-support').install = () => {} into your playwright.config.ts in line 1.