forwardemail / forwardemail/superagent

[fix] "Object prototype may only be an Object or null: undefined" from supertest in browser contexts

Open
#1,840 0 comments 0 reactions 0 assignees View on GitHub
Bug
Dominant language
JavaScript
Stars
16.6k
Forks
1.3k
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.

## 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.