Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Error: Requiring @playwright/test second time when running some tests with VS Code Test Explorer #32959

Description

@rokbjc

Version

1.47.2

Steps to reproduce

  1. Clone my repo at https://github.com/rokbjc/playwright-second-time-bug
  2. navigate to root of the repo
  3. npm i
  4. npm run build
  5. cd main
  6. 'npm run test'
  7. code . to open Visual Studio Code
  8. open Test Explorer
  9. run both tests

Expected behavior

All tests in Test explorer should pass

Actual behavior

The test in tests\with-reference.spec.ts with reference on the package lib which imports @playwright/test fail.˛

Output:

Running global setup if any…

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

   at ..\playwright.config.ts:1

> 1 | import { defineConfig } from '@playwright/test';
    | ^
  2 |
  3 | export default defineConfig({
  4 |   testDir: './tests',

    at Object.<anonymous> (c:\temp\playwright-second-time-bug\node_modules\playwright\lib\index.js:69:33)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Object.i.<computed>.ut._extensions.<computed> [as .js] (c:\temp\playwright-second-time-bug\node_modules\playwright\lib\utilsBundleImpl.js:16:1010)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1127:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.<anonymous> (c:\temp\playwright-second-time-bug\node_modules\playwright\test.js:17:13)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Object.i.<computed>.ut._extensions.<computed> [as .js] (c:\temp\playwright-second-time-bug\node_modules\playwright\lib\utilsBundleImpl.js:16:1010)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1127:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.<anonymous> (c:\temp\playwright-second-time-bug\node_modules\@playwright\test\index.js:17:18)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Object.i.<computed>.ut._extensions.<computed> [as .js] (c:\temp\playwright-second-time-bug\node_modules\playwright\lib\utilsBundleImpl.js:16:1010)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1127:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.<anonymous> (c:\temp\playwright-second-time-bug\main\playwright.config.ts:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module.f._compile (c:\temp\playwright-second-time-bug\node_modules\playwright\lib\utilsBundleImpl.js:16:994)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Object.i.<computed>.ut._extensions.<computed> [as .ts] (c:\temp\playwright-second-time-bug\node_modules\playwright\lib\utilsBundleImpl.js:16:1010)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1127:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at requireOrImport (c:\temp\playwright-second-time-bug\node_modules\playwright\lib\transform\transform.js:204:18)
    at loadUserConfig (c:\temp\playwright-second-time-bug\node_modules\playwright\lib\common\configLoader.js:94:83)
    at loadConfig (c:\temp\playwright-second-time-bug\node_modules\playwright\lib\common\configLoader.js:105:28)
    at deserializeConfig (c:\temp\playwright-second-time-bug\node_modules\playwright\lib\common\configLoader.js:91:10)
    at LoaderMain.loadTestFile (c:\temp\playwright-second-time-bug\node_modules\playwright\lib\loader\loaderMain.js:43:20)
    at process.<anonymous> (c:\temp\playwright-second-time-bug\node_modules\playwright\lib\common\process.js:95:22)

Second: 
    at Object.<anonymous> (c:\temp\playwright-second-time-bug\node_modules\@playwright\test\index.js:17:18)
    at Object.<anonymous> (c:\temp\playwright-second-time-bug\main\playwright.config.ts:1:1)
    at Object.<anonymous> (C:\temp\playwright-second-time-bug\node_modules\playwright\lib\index.js:64:11)
    at Object.<anonymous> (C:\temp\playwright-second-time-bug\node_modules\playwright\test.js:17:13)
    at Object.<anonymous> (C:\temp\playwright-second-time-bug\node_modules\@playwright\test\index.js:17:18)
    at Object.<anonymous> (C:\temp\playwright-second-time-bug\lib\src\env.ts:1:1)
    at Object.<anonymous> (c:\temp\playwright-second-time-bug\main\tests\with-reference.spec.ts:2:1)

Running 1 test using 1 worker

  ✓  1 without-reference.spec.ts:3:5 › test (9ms)

  1 passed (2.2s)
  1 error was not a part of any test, see above for details

Additional context

No response

Environment

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
    Memory: 11.70 GB / 31.76 GB
  Binaries:
    Node: 22.9.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 4.5.0 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.8.3 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.7.1 - ~\AppData\Local\pnpm\pnpm.EXE
  IDEs:
    VSCode: 1.94.0 - C:\Users\rok\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD
  Languages:
    Bash: 5.2.21 - C:\WINDOWS\system32\bash.EXE

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions