Skip to content

Support Express 5 stable and fix async handler errors - #10

Merged
alecgibson merged 1 commit into
mainfrom
express-5-stable-compat
Mar 19, 2026
Merged

Support Express 5 stable and fix async handler errors#10
alecgibson merged 1 commit into
mainfrom
express-5-stable-compat

Conversation

@alecgibson

Copy link
Copy Markdown
Collaborator

Summary

  • Bumps peerDependencies and devDependencies from the alpha Express 5 range (^5.0.0-alpha.1 / ^5.0.0-alpha.6) to the stable ^5.0.0.
  • Makes wrapMiddleware async and awaits the user-supplied handler, so rejected promises from async WebSocket handlers are caught by the try/catch and forwarded to next(err) instead of becoming silent unhandled rejections. This also lets Express 5's own promise-handling layer catch any uncaught rejections from the wrapper itself.
  • Backwards-compatible with Express 4: errors are still forwarded via next(err), not relying on Express 5 promise handling.

Test plan

  • npm install — no peer dependency conflicts with express@5.
  • Run an example (node examples/simple.js) against Express 5 and confirm WebSocket connections work.
  • Test with an async WebSocket handler that throws — confirm the error reaches Express error middleware rather than becoming an unhandled rejection.

🤖 Generated with Claude Code

- Bump peerDependencies and devDependencies from `^5.0.0-alpha.1/6`
  to `^5.0.0` to target the Express 5 stable release.
- Make `wrapMiddleware` async and await the user handler so that
  rejected promises from async WebSocket handlers are caught by the
  try/catch and forwarded to `next(err)` rather than becoming silent
  unhandled rejections. Backwards-compatible with Express 4.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@alecgibson
alecgibson force-pushed the express-5-stable-compat branch from 5f13a4d to 1997ce9 Compare March 19, 2026 13:18
@alecgibson
alecgibson marked this pull request as ready for review March 19, 2026 13:18
@alecgibson
alecgibson requested review from a team and Copilot March 19, 2026 13:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the package to support stable Express 5 and ensures async WebSocket handlers have their rejected promises/errors forwarded into Express error handling (instead of becoming unhandled rejections), while maintaining Express 4 compatibility via next(err).

Changes:

  • Bump Express peer/dev dependency ranges from Express 5 alpha to stable ^5.0.0.
  • Make wrapMiddleware async and await the user-supplied handler to catch async rejections and forward them to next(err).
  • Update the package version to 5.0.0-reedsy-5.1.0.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/wrap-middleware.js Awaits user middleware to catch async errors and forward to next(err).
package.json Updates Express peer/dev dependency ranges and bumps package version.
Comments suppressed due to low confidence (1)

package.json:32

  • peerDependencies.express is expanded to include Express 5, but engines.node still claims support for Node >=4.5.0, which cannot run this package as ESM ("type": "module") and also won’t support the newly added async/await usage. Please update the engines.node range to reflect the actual minimum supported Node version (and, if applicable, align it with the Node version used in CI via .nvmrc).
    "express": "^4.0.0 || ^5.0.0"
  },
  "engines": {
    "node": ">=4.5.0"
  },

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/wrap-middleware.js
@@ -1,10 +1,10 @@
export function wrapMiddleware(middleware) {
return (req, res, next) => {
return async (req, res, next) => {
@alecgibson
alecgibson merged commit 8061dd7 into main Mar 19, 2026
6 checks passed
@alecgibson
alecgibson deleted the express-5-stable-compat branch March 19, 2026 13:24
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