#867·supertest

[fix] Trouble using cypress with supertest since 6.2.4

Author: coddersCreated Aug 11, 2025Updated Aug 12, 2025
Labelsbug

Describe the bug

Node.js version: 20.10.0

OS version: debian trixie/sid

Description: Including supertest in a cypress project results in the error Object prototype may only be an Object or null: undefined when supertest tries to include superagent.

I think this might also be related to changes in the way Webpack 5 stubs packages with node dependencies. With a bit of debug I can see that 'superagent' is being stubbed by Webpack, which could be a symptom of superagent relying on native libraries that Webpack cannot bundle / aren't available in a web context.

I have tried playing around with the webpack configuration to stub the node libraries, but haven't had much luck.

Actual behavior

Creating a blank cypress project and including supertest as a requirement in any spec file generates the error

Object prototype may only be an Object or null: undefined

With the backtrace:

      at Function.setPrototypeOf (<anonymous>)
      at ./node_modules/supertest/lib/agent.js (webpack://cypress-supertest-issue-minimal/./node_modules/supertest/lib/agent.js:36:0)
      at __webpack_require__ (webpack://cypress-supertest-issue-minimal/webpack/bootstrap:19:0)
      at ./node_modules/supertest/index.js (webpack://cypress-supertest-issue-minimal/./node_modules/supertest/index.js:9:14)
      at __webpack_require__ (webpack://cypress-supertest-issue-minimal/webpack/bootstrap:19:0)
      at eval (webpack://cypress-supertest-issue-minimal/./cypress/e2e/spec.cy.js:1:18)

Expected behavior

It should be possible to require (and use) the library without issue, as was the case until version 6.2.4.

Code to reproduce

I created an example project with a minimal reproduction here: https://github.com/codders/cypress-supertest-issue-minimal

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.