Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: @playwright/experimental-ct-react does not export package.json, which breaks VS Code extension #31491

Closed
glacius-mitchell opened this issue Jun 30, 2024 · 0 comments · Fixed by #31504

Comments

@glacius-mitchell
Copy link

glacius-mitchell commented Jun 30, 2024

Version

1.45.0

Steps to reproduce

  1. Start a fresh Debian dev container in VS Code.

  2. Install Node.js via the instructions at https://github.com/nodesource/distributions?tab=readme-ov-file#installation-instructions-deb.

  3. Enable Corepack via sudo corepack enable.

  4. Initialize a Playwright project via pnpm create playwright. Note that it uses @playwright/test.

  5. Install the Playwright Test extension (https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright).

  6. Go to the Testing tab and observe that tests/example.spec.ts is listed as expected.

Screenshot 2024-06-29 at 8 03 29 PM

  1. Run pnpm remove @playwright/test && pnpm add --save-dev @playwright/experimental-ct-react.

  2. Go to the Testing tab and observe that tests/example.spec.ts is no longer detected when using @playwright/experimental-ct-react instead of @playwright/test.

Screenshot 2024-06-29 at 8 04 44 PM

Expected behavior

I expect the Playwright Test extension for VS Code to work the same whether I'm using @playwright/test or @playwright/experimental-ct-react.

Actual behavior

The Playwright Test extension for VS Code works with @playwright/test but not with @playwright/experimental-ct-react.

Additional context

If we take a look at https://github.com/microsoft/playwright-vscode/blob/v1.1.7/src/playwrightFinder.ts#L33, we see that the VS Code extension is trying to load @playwright/experimental-ct-react's package.json file as follows:

packageJSONPath = require.resolve(path.join(packageName, 'package.json'), { paths: [process.cwd()] });

This is fine for @playwright/test since it exports package.json:

"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.mjs",
"require": "./index.js",
"default": "./index.js"
},
"./cli": "./cli.js",
"./package.json": "./package.json",
"./reporter": "./reporter.js"
},

However, this doesn't work for @playwright/experimental-ct-react since it doesn't export package.json:

"exports": {
".": {
"types": "./index.d.ts",
"default": "./index.js"
},
"./register": {
"types": "./register.d.ts",
"default": "./register.mjs"
},
"./hooks": {
"types": "./hooks.d.ts",
"default": "./hooks.mjs"
}
},

Indeed, if we run that line of code in a test script, we encounter the following error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /workspaces/debian/node_modules/@playwright/experimental-ct-react/package.json

Suggested fix

The fix should be as simple as adding a "./package.json": "./package.json" entry to the exports section of @playwright/experimental-ct-react's package.json file.

Note that you'll probably want to do the same for the other @playwright/experimental-ct-* packages as well.

Environment

System:
    OS: Linux 6.6 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (12) arm64 unknown
    Memory: 19.30 GB / 23.44 GB
    Container: Yes
  Binaries:
    Node: 22.3.0 - /usr/bin/node
    npm: 10.8.1 - /usr/bin/npm
    pnpm: 9.4.0 - /usr/bin/pnpm
  IDEs:
    VSCode: 1.90.2 - /vscode/vscode-server/bin/linux-arm64/5437499feb04f7a586f677b155b039bc2b3669eb/bin/remote-cli/code
  Languages:
    Bash: 5.1.4 - /bin/bash
  npmPackages:
    @playwright/experimental-ct-react: ^1.45.0 => 1.45.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant