microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.32k stars 3.63k forks source link

[BUG] Types no longer exported from @playwright/test #27860

Closed ericmatthys closed 11 months ago

ericmatthys commented 11 months ago

System info

Source code

import type { TestInfo } from '@playwright/test';
import type { PlaywrightTestConfig } from '@playwright/test';

Expected

With 1.37.1, these imports are valid.

Actual

TS2614: Module  "@playwright/test"  has no exported member  TestInfo . TS2614: Module  "@playwright/test"  has no exported member  PlaywrightTestConfig .

I didn't see anything in the release notes that indicates that this is an expected breaking change.

pavelfeldman commented 11 months ago

I can't repro this. Please follow the BUG template to provide exact steps I can follow to reproduce this, starting with npm init playwright@latest

alexkuc commented 11 months ago

@ericmatthys Check your local paths. Playwright have internally renamed some packages (#26946) and if you have the same folders/files as Playwright's, TypeScript might erroneously resolve those against your local packages instead of node_module's ones.

Simple way to reproduce the issue:

export * from 'playwright/test';
export { default } from 'playwright/test';

In my case, I actually have a local file playwright/test.ts and when I click on those namespaces, my IDE opens my local file, not Playwright's types

ericmatthys commented 11 months ago

It seems to be an issue with how pnpm is installing dependencies in a monorepo using symlinks, despite TS being configured to preserve sym links. Adding playwright as an explicit dependency as well as @playwright/test fixes the TS errors, despite playwright already being a dependency of @playwright/test. I'll take a closer look at what is happening there.

ericmatthys commented 11 months ago

More context: https://github.com/orgs/pnpm/discussions/5535

Adding public-hoist-pattern[]=playwright to .npmrc is another way of fixing the issue

alexkuc commented 11 months ago

My solution to this is to use paths in tsconfig.json:

"paths": {
    "playwright/test": ["node_modules/playwright/test"]
}

since I am not using pnpm

garrappachc commented 4 months ago

More context: https://github.com/orgs/pnpm/discussions/5535

Adding public-hoist-pattern[]=playwright to .npmrc is another way of fixing the issue

Stumbled upon this issue recently, I'm using pnpm. For me, the fix was to actually put

public-hoist-pattern[]=playwright*

in the .npmrc. The playwright-core package needs to be present as well.