-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update base-server.ts #64926
base: 14-2-1
Are you sure you want to change the base?
Update base-server.ts #64926
Conversation
fixed Error handling upgrade request TypeError: Cannot read properties of undefined (reading 'bind')
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, can you add a test case for this that fails without the change, this doesn't seem like a full fix if _res.setHeader
is having issues here.
Failing test suitesCommit: e19d91c
Expand output● Next Lint › First Time Setup › installs eslint and eslint-config-next as devDependencies if missing with yarn
● Next Lint › First Time Setup › creates .eslintrc.json file with a default configuration
● Next Lint › First Time Setup › creates .eslintrc.json file with a default app router configuration
● Next Lint › First Time Setup › shows a successful message when completed
Read more about building and testing Next.js in contributing.md.
Expand output● node builtins › should support node.js builtins in server component
● node builtins › should support node.js builtins prefixed by node: in server component
Read more about building and testing Next.js in contributing.md. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, could you add a test case where this is failing?
I'm encountering this exact failure while trying to implement a micro-frontends app using Turbo & NextJs rewriting feature (via middlewares). I needed to implement a routing system that check both for auth and micro-app availability and handle a decent redirection/error page. All is good and I succeeded to get a chain of middleware that work in harmony and did what's needed but unfortunately not the webpack's HMR. The related socket keeps failing due to this (bind "undefined") issue. Which offcourse affects 📉 hugely our DX. After hours of digging, It seems like the ws upgrade query did it. It keeps returning http error (produced by the use case code fail), then, it retries without any success.. after around a minute of retries, it refresh the window automatically. Finally, When I forced the suggested code by @Talentaa in |
@MalekBouba are you using a custom server? If so could you show the setup in a minimal repro so we could add a test case for this? |
@ijjk We're not, we tried to stick with the official, standard tools, no custom servers, no overrides. Here is how we do this: import { type NextRequest, NextResponse } from "next/server";
export default function MyRoutingMiddleware(request: NextRequest) {
if (myCondition) return NextResponse.redirect(/*...*/);
if (myCondition) return NextResponse.rewrite(/*...*/);
return undefined;
} and, import { NextResponse } from 'next/server'
import { NextMiddlewareResult } from 'next/dist/server/web/types'
import NextAuth from 'next-auth'
const { auth } = NextAuth(authConfig)
export function MyAuthMiddleware(middleware: any): any | NextMiddlewareResult {
return auth((request) => {
const response = NextResponse.next()
if (myCondition) return NextResponse.next()
if (!request.auth) return NextResponse.redirect(/*...*/)
return middleware(request, undefined, response)
})
} then, import { type NextRequest, NextResponse } from "next/server";
import MyAuthMiddleware from "middlewares/a";
import MyRoutingMiddleware from "middlewares/b";
const middlewares = [MyAuthMiddleware, MyRoutingMiddleware];
export default async function middleware(request: NextRequest) {
for (const fn of middlewares) {
const response = await fn(request);
if (response) return response;
}
return NextResponse.next();
} PS: export const config = {
matcher: [
'/((?!api|_next/static|_next/image|_next/data|/__nextjs_original-stack-frame|assets|favicon.ico|sitemap.xml|robots.txt).*)',
],
} Everything work fine in prod, we just suffer bad DX in dev env. |
@MalekBouba does the issue resolve if you add |
Unfortunately, no, it doesn't. that's what we tried first.
Do you need clone project for minimal reproduction? |
Seeing the project would make adding a test case much easier! |
I'll work on it. |
fixed Error handling upgrade request TypeError: Cannot read properties of undefined (reading 'bind')
issue url #55802