question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] "Requiring @playwright/test second time" when using shared package

See original GitHub issue

Code Snippet

https://github.com/Forfold/playwright-test

Describe the bug

Related to #15349 and #11889

I have a playwright-auth package I’m creating to handle some login stuff that I plan to use in multiple repos I’m working on. playwright-auth exports a login() and a globalLogin() function. I’ve created the above repo playwright-test acting as my auth package.

I see Error: Requiring @playwright/test second time but both repos utilize @playwright/test for different reasons.

My playwright-auth package utilizes chromium, expect, request, and Page.

My website repos use test and expect

Full error output:

Running 0 test using 0 worker


Error: Requiring @playwright/test second time, 
First:
Error: 

   at node_modules/@playwright/test/lib/index.js:73

  71 |   }
  72 | } else {
> 73 |   process['__pw_initiator__'] = new Error().stack;
     |                                 ^
  74 | }
  75 |
  76 | const test = _baseTest.extend({

    at Object.<anonymous> (/Users/Z0027PF/git/playwright-test/example/node_modules/@playwright/test/lib/index.js:73:33)
    at Module._compile (node:internal/modules/cjs/loader:1120:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
    at Module.load (node:internal/modules/cjs/loader:998:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1022:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/Z0027PF/git/playwright-test/example/node_modules/@playwright/test/index.js:17:13)
    at Module._compile (node:internal/modules/cjs/loader:1120:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
    at Module.load (node:internal/modules/cjs/loader:998:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1022:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/Z0027PF/git/playwright-test/example/playwright/login.spec.ts:1:1)

Second: 
    at Object.<anonymous> (/Users/Z0027PF/git/playwright-test/example/node_modules/playwright-test/node_modules/@playwright/test/lib/index.js:68:11)
    at Object.<anonymous> (/Users/Z0027PF/git/playwright-test/example/node_modules/playwright-test/node_modules/@playwright/test/index.js:17:13)
    at Object.<anonymous> (/Users/Z0027PF/git/playwright-test/example/node_modules/playwright-test/dist/index.js:16:16)
    at Object.<anonymous> (/Users/Z0027PF/git/playwright-test/example/playwright/login.spec.ts:5:23)

=================
 no tests found.
=================

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dgozmancommented, Jul 25, 2022

@Forfold We have to reproduce this issue to be able to debug it. If you can provide a full repro that we can replicate locally, please file a new issue with it, and link to this one.

0reactions
Forfoldcommented, Jul 26, 2022

playwright.config.ts seems to be in the wrong place, based on the relative paths it uses mv src/playwright.config.ts .

From your comment @dgozman it looks like I may need a second config file for playwright in my repo. The config included there is for the example website only.

However, regarding installing the package from a tgz file, I don’t know if I would expect my users to do that. I would assume that importing login should work out of the box if they install my playwright-auth package with npm and have their own playwright config setup.

I’ll do some more exhaustive testing locally. I don’t really have it in me to host a dummy package on NPM just for this example.

There will be no relative pathing in a real world situation is what I’ve been trying to explain


edit: looks like adding a second config may have solved the issue. I would think that a config wouldn’t be needed for the helper package since it’s not a test runner, but I’ll take it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Cannot find module '@playwright/test' - Stack Overflow
The test works fine without this: const { expect } = require('@playwright/test'); const { matchers } = require('playwright-expect'); console. ...
Read more >
[BUG] "Requiring @playwright/test second time" when using ...
I have a playwright-auth package I'm creating to handle some login stuff that I plan to use in multiple repos I'm working on....
Read more >
E2E Testing with Playwright - JointJS
Playwright requires Node.js version 12 or above. Run node -v from the command line to make sure you have a compatible version of...
Read more >
How To Run End-to-End Tests Using Playwright and Docker
In this tutorial, you will set up an environment to use Playwright with Typescript for end-to-end testing, write and execute the tests, ...
Read more >
Advanced: configuration | Playwright - CukeTest
forbidOnly: boolean - Whether to exit with an error if any tests are marked as test.only . Useful on CI. globalSetup: string -...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found