playwright: [BUG] Getting "Please install @playwright/test package to use Playwright Test."

Context:

System:

  • OS: Linux 5.4 Ubuntu 21.04 (Hirsute Hippo)
  • Memory: 502.32 MB / 15.52 GB
  • Container: Yes

Binaries:

  • Node: 15.14.0 - ~/.volta/tools/image/node/15.14.0/bin/node
  • Yarn: 1.22.10 - ~/.volta/tools/image/yarn/1.22.10/bin/yarn
  • npm: 7.15.0 - ~/.volta/tools/image/npm/7.15.0/bin/npm

Languages:

  • Bash: 5.1.4 - /usr/bin/bash

npmPackages:

  • playwright: ^1.12.0 => 1.12.0

Describe the bug

I just installed playwright version 1.12 to try out the new test runner but I am consistently getting Please install @playwright/test package to use Playwright Test. no matter how many times I do yarn add --dev @playwright/test.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 29 (5 by maintainers)

Most upvoted comments

Had the same issue, because previous beta versions of @playwright/test did require playwright.

Solution:

  • npm rm playwright
  • npm install @playwright/test -D

Then it works.

If anyone else ends up here looking for a solution. The root cause of this problem is that the playwright package and the @playwright/test package both provide a cli tool named playwright. The one in the playwright package just throws this error if you attempt to run playwright test or something else.

If you have both packages installed then whether playwright test works or not depends entirely on what order they were installed in. If playwright was installed last then it won’t work, if @playwright/test was installed last then it will work.

If you need to have both installed, the only way I’ve found to work around this is to install postinstall-postinstall and add a postinstall script that does this:

cd node_modules/.bin
ln -sf ../@playwright/test/cli.js playwright

This will force the symlink to the package to be replaced with the @playwright/test version every time you run npm install (or yarn install, or whatever).

@jasonk thanks for the pointer! I used a different workaround - pass the full path to cli.js in package.json’s scripts.test:

-    "test": "playwright test",
+    "test": "node_modules/@playwright/test/cli.js test",

You don’t need playwright when using @playwright/test:

yarn init -y
yarn add --dev @playwright/test
npx playwright test

Why I can’t use both. In our project we use monorepo. And one of application in this monorepo uses crawlee: https://www.npmjs.com/package/crawlee

where in dependencies it use playwright. So now we have to choose should we test out product, or use one of our critical application. And it means that we need to use cypress instead of playwright for testing or other framework.

In my case,

Success!!!

You don’t need playwright when using @playwright/test:

yarn init -y
yarn add --dev @playwright/test
npx playwright test

The solutions above did not work for me, I couldn’t figure out how to get past

Please install @playwright/test package to use Playwright Test.
  npm install -D @playwright/test

… when running npx playwright test.

Resolved by running yarn playwright test instead of npx playwright test.

See also https://github.com/microsoft/playwright/issues/8495 for another snag one may encounter when using Yarn 2 PnP and @playwright/test (will likely be fixed in the next release).

(props to @merceyz)

I ran into this issue because I had test in my .yarnclean file. Yarn removed the lib/test folder and the entire node_modules/@playright/test folder because of this 🤦

I fixed by adding this to .yarnclean:

!@playwright/test/**

i just encountered this issue. it really is problematic and counter intuitive that both packages have the same cli name and conflict. i think the best way forward (altough it breaks a lot of package.json script and ci pipelines) to change the name of the playwright test script and resolve the conflict. it is quite shame but i probably use puppeteer again. there are multiple use case for testing and automation in one “project”. would love to use playwright again in the future

For anybody experiencing this after upgrading to 1.34.0 (I am), I think this may be related to https://github.com/microsoft/playwright/issues/23098

Note/question: for projects using Playwright for both unit tests and e2e tests, could this be a problem? or is @playwright/test-only the way to go in this scenario?

I had this issue in a repo using npm workspaces. npx playwright install gave a not found error when run in the root. When I changed to run it inside the workspace package that needed playwright instead it worked fine.

I’ve been trying everything I can think of to get testing to work in an Azure Pipeline.

My YAML:

resources:
  containers:
  - container: playwright
    image: mcr.microsoft.com/playwright:focal

  repositories:
  - repository: self
    type: git
    ref: refs/heads/develop

jobs:
- job: e2e_testing
  container: playwright
  displayName: E2E Testing

  pool:
    vmImage: ubuntu-latest

  steps:
  - checkout: self

  - script: |
      yarn
      npx playwright test
    displayName: 'Run test'

  - task: PublishTestResults@2
    inputs:
      testResultsFormat: 'JUnit'
      testRunTitle: 'Test Report'
    displayName: 'Publish Reports'

but I get…

Please install @playwright/test package to use Playwright Test.
  npm install -D @playwright/test
##[error]Bash exited with code '1'.

If I try to use yarn playwright test, then I get…

yarn run v1.22.11
$ playwright test
/bin/sh: 1: playwright: not found
error Command failed with exit code 127.

What is the magic combination to make this work??