forwardemail / forwardemail/supertest

[fix] Trouble using cypress with supertest since 6.2.4

Open
#867 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
14.4k
Forks
782
PR merge metrics
No merged PRs in 30d

Description

## 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 ()
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

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.