You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hosting rewrites are not working on emulators when using Next.js with webframeworks #5840
Receive a response from helloworld firebase function
[REQUIRED] Actual behavior
Receive a 404 error page from Next.js app
Why is this happening?
This bug is related to pull request #5582. It was released in version 11.25.3.
Firebase hosting emulator is basically the superstatic server. firebase-tools using it to create a dev server with the superstaticstrict stack which is ["redirects", "headers", "files", "rewrites", "missing"]. Also, firebase-tools adding functions before and after files part. So the resulting request processing pipeline is the following:
Check redirects
Check headers
Check firebase service urls
Check files
Check Next.js app response
Check rewrites
Check missing
In the pull request #5582createServerResponseProxy function was replaced with the simpleProxy function. But createServerResponseProxy had the following piece of code, that is currently missing:
if (proxiedRes.statusCode === 404) {
next();
}
It means that before, if the route is not found in the Next.js app the request pipeline would continue to evaluate rewrites and missing. And now, it just returns the response from Node.js app and ignores rewrites and missing.
As the result the whole rewrites section under hosting in firebase.json is ignored.
@jamesdaniels Seems like fix is not working for me. Getting the following error message after upgrade to 12.3.0:
Error [ERR_HTTP_HEADERS_SENT]: Cannot render headers after they are sent to the client
at new NodeError (node:internal/errors:399:5)
at ServerResponse.writeHead (node:_http_server:382:13)
at ServerResponse.writeHead (/path-to-my-project/node_modules/on-headers/index.js:44:26)
at ServerResponse.writeHead (/path-to-my-project/node_modules/on-headers/index.js:44:26)
at ServerResponse.writeHead (/path-to-my-project/node_modules/next/dist/compiled/compression/index.js:46:263)
at ServerResponse.writeHead (/path-to-my-project/node_modules/next/dist/compiled/compression/index.js:46:263)
at /path-to-my-project/node_modules/firebase-tools/lib/frameworks/utils.js:46:18
at /path-to-my-project/node_modules/firebase-tools/lib/frameworks/utils.js:98:45
i hosting: 127.0.0.1 - - [03/Jun/2023:14:08:06 +0000] "GET /api/helloworld HTTP/1.1" 500 - "-" "PostmanRuntime/7.32.2"
That make sense since hostOrRequestHandler is called before proxy with original response.
I also am getting that error when using Firebase Emulator Tools (using the "web frameworks" logic to host a Next.JS site). I'm not defining any specific redirects, but Next.JS does redirects under the hood. When using firebase-tools v12.3.0, that error of "Cannot render headers after they are sent to the client" happens for files that aren't the main index file (e.g. /_next/static/chunks/node_modules_foo.js).
Downgrading to [email protected] made this issue go away for my environment.
Activity
jamesdaniels commentedon May 16, 2023
Great catch, we'll get that functionality back into simpleProxy
Continue on 404, baseUrl for Next rewrites (#5923)
nikita-mishchenko commentedon Jun 3, 2023
@jamesdaniels Seems like fix is not working for me. Getting the following error message after upgrade to 12.3.0:
That make sense since
hostOrRequestHandleris called before proxy with original response.MidnightLightning commentedon Jun 14, 2023
I also am getting that error when using Firebase Emulator Tools (using the "web frameworks" logic to host a Next.JS site). I'm not defining any specific redirects, but Next.JS does redirects under the hood. When using
firebase-toolsv12.3.0, that error of "Cannot render headers after they are sent to the client" happens for files that aren't the main index file (e.g./_next/static/chunks/node_modules_foo.js).Downgrading to
[email protected]made this issue go away for my environment.jasan-s commentedon May 30, 2024
This still seems like an issue using next js with firebase hosting , i cant use