fix: resolve Next.js 15.5+ route handler type compatibility issues#29
fix: resolve Next.js 15.5+ route handler type compatibility issues#29asionesjia wants to merge 2 commits intologtail:mainfrom
Conversation
- Fix withBetterStack return type to properly return NextHandler instead of BetterStackRouteHandler - Separate BetterStackRouteHandler (user-facing) from NextHandler (Next.js-facing) types - Ensure backward compatibility with Next.js 14 while supporting Next.js 15.5+ This resolves TypeScript errors in Next.js 15.5+ where route handlers were failing type checks due to incompatible Request types between BetterStackRequest and NextRequest.
Reverted Next.js from 15.5.3 to 14.0.0 and React from beta to 18.2.0 to resolve build issues with type incompatibilities between different Next.js versions in the monorepo.
|
I reverted the version update for I didn’t attempt a full dependency upgrade yet, since many dependencies are still on older versions and I’m not certain whether upgrading everything now would cause additional issues. Since this bug is blocking builds on |
|
Hi @asionesjia and thanks for the PR 🙌 We're tracking the issue of incompatibility with the newer Next.js version internally, and while I can't provide any ETA just yet, I'll try to make sure this gets prioritized to unblock builds based on v15.5.0 or higher without relying on a forked package. Thanks for bringing it to our attention and suggesting a specific update 🙏 |
|
+1 |
1 similar comment
|
+1 |
|
Thank you for your patience 🙏 We've been planning on tackling the Next.js 15 and 16 compatibility for quite some time, it should be released as |
|
Happy to report the There are minimal changes in the usage which you can check in our docs. Hope it helps 🙌 I'd be happy to hear your feedback! |
Summary
This PR fixes TypeScript compatibility issues with Next.js 15.5+ route handlers while maintaining backward compatibility with Next.js 14.
Problem
In Next.js 15.5+, the type checking for route handlers became stricter, causing the following error:
Solution
The issue was in the type signature of the
withBetterStackfunction. Previously, it was incorrectly returningBetterStackRouteHandlerwhen wrapping route handlers, but it should returnNextHandlersince:BetterStackRouteHandler- The handler written by users that expectsBetterStackRequest(withlogproperty)NextHandler- The handler that Next.js can use, accepting standardNextRequestlogproperty internally, bridging the gap between the two typesChanges Made
BetterStackRouteHandler(user-facing type) fromNextHandler(Next.js-facing type)withBetterStackoverload fromBetterStackRouteHandlertoNextHandlerwithBetterStackRouteHandlerto properly handle the type transformationTesting
✅ Updated example/logger to Next.js 15.5.3 to verify the fixBreaking Changes
None. This fix is fully backward compatible.
Related Issues
Fixes compatibility issues with Next.js 15.5+ strict type checking for route handlers.