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)
Had the same issue, because previous beta versions of
@playwright/testdid requireplaywright.Solution:
npm rm playwrightnpm install @playwright/test -DThen it works.
If anyone else ends up here looking for a solution. The root cause of this problem is that the
playwrightpackage and the@playwright/testpackage both provide a cli tool namedplaywright. The one in theplaywrightpackage just throws this error if you attempt to runplaywright testor something else.If you have both packages installed then whether
playwright testworks or not depends entirely on what order they were installed in. Ifplaywrightwas installed last then it won’t work, if@playwright/testwas 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
postinstallscript that does this:This will force the symlink to the package to be replaced with the
@playwright/testversion every time you runnpm install(oryarn 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: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
playwrightwhen using@playwright/test:The solutions above did not work for me, I couldn’t figure out how to get past
… when running
npx playwright test.Resolved by running
yarn playwright testinstead ofnpx 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
testin my.yarncleanfile. Yarn removed thelib/testfolder and the entirenode_modules/@playright/testfolder because of this 🤦I fixed by adding this to
.yarnclean: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 installgave anot founderror 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:
but I get…
If I try to use
yarn playwright test, then I get…What is the magic combination to make this work??