Skip to content

Require Node 26 and update superagent to fix crash on redirecting images - #5

Open
jeremywarrick wants to merge 2 commits into
BHSPitMonkey:mainfrom
jeremywarrick:fix/superagent-redirect-node24
Open

jeremywarrick wants to merge 2 commits into
BHSPitMonkey:mainfrom
jeremywarrick:fix/superagent-redirect-node24

Conversation

@jeremywarrick

@jeremywarrick jeremywarrick commented Nov 9, 2026 •

Copy link
Copy Markdown

Summary

Articles with a redirecting image (e.g. GitHub README badges) crash the server on Node 24+. This PR makes Node 26 the minimum and updates superagent so redirects work on it.

Why updating Node alone wasn't enough

epub-gen downloads images with superagent@3.8.3, whose redirect handler reads Node's private ClientRequest#_headers (DEP0066). That property only exists up to Node 22; on 24+ it's undefined, so every redirect throws an uncaught TypeError and the process exits. Raising the minimum to 26 by itself would make the crash happen everywhere, so superagent had to be updated too.

Changes

  • Node 26 minimum: engines.node >= 26.0.0, @types/node ^26, .nvmrc v26, Dockerfile FROM node:26, README note.
  • superagent update: a resolutions entry points epub-gen's superagent@^3.8.3 at ^10.4.2. 10.x reads headers through the public getHeaders() API and still supports the get().set().pipe() calls and end/error events that epub-gen uses. No patch files and no src/ changes.
  • yarn.lock and .pnp.cjs regenerated.

Testing (Raspberry Pi 5, Node 26.7.0)

  • Redirect repro (301→302→303→200): superagent 3.8.3 crashes, while 10.4.2 completes with the correct bytes.
  • The article that crashed the server: now returns a valid 567 KB EPUB with images, and the server doesn't restart.
  • All 12 current HN front-page articles: valid EPUBs, with 53 image downloads, no errors and no restarts.
  • Docker-style clean install (only package.json, yarn.lock and dist/): installs and serves correctly. docker build itself wasn't run because Docker isn't available on this machine.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EpKf8M1442k2PDhNiHy9ij

epub-gen downloads article images with superagent 3.8.3, whose redirect
handler reads the private `ClientRequest#_headers` property. Node.js
removed that property (DEP0066 end-of-life; it is `undefined` on Node 24,
25 and 26), so `utils.cleanHeader(undefined)` throws
"TypeError: Cannot convert undefined or null to object" from inside a
socket callback. That exception is uncaught and terminates the whole
server process whenever an article contains an image URL that returns a
301/302/303 redirect.

Patch superagent via `yarn patch` to read headers through the public
`getHeaders()` API (falling back to `_headers` on old runtimes), and copy
`.yarn/patches/` into the Docker build context so the patched resolution
installs inside the image.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EpKf8Li5Lv7SsxKXrMvGZP
@BHSPitMonkey

Copy link
Copy Markdown
Owner

Thanks for submitting.

Rather than patching the dependency to shim in support for both new/old Nodes, I think I'd rather just bump the project's Node requirement up to >=24 (or probably just 26, the current LTS). I will try to get to this when I can, but if you're interested in taking that on I'll be happy to merge it in as well!

@jeremywarrick

Copy link
Copy Markdown
Author

that sounds even better, let me (have Fable) give it a go!

Per review on BHSPitMonkey#5: rather than shimming superagent 3.8.3 to work on both old
and new Node versions, raise the project's Node requirement to 26 (current
LTS) and resolve epub-gen's superagent dependency to the maintained 10.x line,
which reads request headers through the public getHeaders() API.

- package.json: engines.node ">= 26.0.0"; @types/node ^26; resolution
  superagent@npm:^3.8.3 -> npm:^10.4.2 (replaces the patch: resolution)
- Remove .yarn/patches/superagent-npm-3.8.3-*.patch
- Dockerfile: node:26 base image; drop the .yarn/patches COPY
- .nvmrc: v26
- README: note the Node 26 requirement
- yarn.lock, .pnp.cjs: regenerated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EpKf8M1442k2PDhNiHy9ij
@jeremywarrick jeremywarrick changed the title Fix server crash when article images redirect on Node.js >= 24 Require Node 26 and update superagent to fix crash on redirecting images Nov 10, 2026
@jeremywarrick

Copy link
Copy Markdown
Author

Thanks for the suggestion! Updated in 8d77770:

  • Raised the Node requirement to 26 (engines, .nvmrc, @types/node, and FROM node:26 in the Dockerfile).
  • Dropped the yarn patch shim. Bumping Node alone would actually make the crash happen everywhere, because superagent 3.8.3 reads _headers, which only Node 22 still has. So I added a resolutions entry that points epub-gen's superagent dependency at 10.4.2, which uses getHeaders().

Tested on a Pi 5 with Node 26: the article that used to crash now converts, all 12 current HN front-page articles converted (53 image downloads, no errors or restarts), and a Docker-style clean install works. Details are in the updated description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants