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

[NPM] Error: Requiring @playwright/test second time - when using 2 separate npm packages #31478

Open
msieorbus opened this issue Jun 28, 2024 · 5 comments

Comments

@msieorbus
Copy link

msieorbus commented Jun 28, 2024

I have two separate npm packages which are on internal organization npm feed.
Lets call them

  • packageA
  • packageB
  • testingProject

all packages using @playwright/test, packageA is "main" one and packageB is using packageA. When i later install packageB to my testingProject i cannot run tests due to Error: Requiring @playwright/test second time

How to create just one instance of playwright/test, i have playwright.config.ts only in my testing project.
I was trying to use only playwright-core in packages but it wont work in my case as i using expect in them which is not included in core.
Maybe i should export @playwright/test from packageA, but then how to setup testing project without it ?

@msieorbus msieorbus changed the title [NPM] Error: Requiring @playwright/test second time when i use 2 packages [NPM] Error: Requiring @playwright/test second time - when using 2 separate npm packages Jun 28, 2024
@pavelfeldman
Copy link
Member

Make sure you are using the same version of Playwright in your packages. Npm will perform all the necessary deduplication. You can find the source of the problem via examining package-lock. Most likely you pinned different playwright versions in your package.json deps.

@msieorbus
Copy link
Author

msieorbus commented Jul 1, 2024

Make sure you are using the same version of Playwright in your packages. Npm will perform all the necessary deduplication. You can find the source of the problem via examining package-lock. Most likely you pinned different playwright versions in your package.json deps.

In my "base" packageA i added in package.json dependencies:
image

so once i install packageA in packageB (packageB have packageA in dependencies) and later install packageB in testing Project it is using those dependencies so versions are for sure the same. I am able to import everything correctly.
However i have still this error when im trying to run my tests...

Error: Requiring @playwright/test second time,

Maybe my playwright.config.ts is in wrong package/place ? It should be only in testing project ?

@mxschmitt
Copy link
Member

Looking at the package-lock.json should usually give a clue on if multiple @playwright/test versions are installed or not. We need something we can clone and reproduce locally in order to triage this further. Thanks for your understanding!

It also depends on how you distribute your util package etc. (esbuild or pure TypeScript etc.)

@msieorbus
Copy link
Author

msieorbus commented Jul 2, 2024

I used TSUP to build package.
I added now @playwright/test as a dev dependencies in all 3 projects.
Ive added packageA and package B to my testing project using yarn add -D //relative-pathto-GZ-tarball (before that i used yarn pack ) i checked yarn lock and it seems that its installted only once (as expected as it is in dev dependencies) but still have this issue however...

@mxschmitt
Copy link
Member

mxschmitt commented Jul 2, 2024

Would it be possible to share a reproduction? Otherwise we are not able to act on it, unfortunately. Thank you!

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

No branches or pull requests

3 participants