vercel / next.js

The React Framework
https://nextjs.org
MIT License
122.59k stars 26.23k forks source link

[Testing with Playwright/MSW]: TypeError: _msw.MockedRequest is not a constructor #67205

Open trm217 opened 3 days ago

trm217 commented 3 days ago

Link to the code that reproduces this issue

https://github.com/trm217/reproduction-nextjs-playwright-msw-issue

To Reproduce

  1. Install dependencies using pnpm i
  2. Build the app using pnpm build
  3. Execute the playwright test using pnpm exec playwright test.

Current vs. Expected behavior

I would expect the error TypeError: _msw.MockedRequest is not a constructor not to be thrown, as it doesn't allow using the testmode feature at all.

The error occurs when ever the import path given in this example is used (this file in the reproduction).

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
Binaries:
  Node: 21.2.0
  npm: 10.2.3
  Yarn: 1.22.22
  pnpm: 9.1.0
Relevant Packages:
  next: 14.2.4 // Latest available version is detected (14.2.4).
  eslint-config-next: 14.2.4
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.5.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Testing

Which stage(s) are affected? (Select all that apply)

Other (Deployed)

Additional context

No response