-
Notifications
You must be signed in to change notification settings - Fork 47
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
Bug: Unable to use Hono in Nextjs 14 App Dir with nodejs runtime #174
Comments
I have the same bug trying to run Hono (large application setup) with Next.js (App router) using Node.js runtime You don't have to specify I think the bug comes from the original |
I can't run on edge for the reason of having to do native connection to Postgres (complained about pg-native needing fs). I was able to use the nodejs runtime with App Router (deploying to Vercel). The difference is I import handle from hono/vercel instead. |
Interesting, yes it is working. We should update the docs. |
On another thought, what's the purpose of the |
Where is the documentation for this runtime setting? I can see docs to the RuntimeKey, but that looks somewhat different than this. I only found out how this works by setting it to something else and look through the error messages. |
@firstian It's here: https://hono.dev/docs/getting-started/vercel#node-js The hono.dev documentation is kinda vague. It doesn't explicitly explain what each line does. For example, the constant Anyone know how to setup so that I can use node.js runtime in my Next.js 14? (actually 15 since is stable now), I will highly appreciate it. |
Yeah the documentation is confusing.
export const config: PageConfig = {
api: {
bodyParser: false,
},
} Edit: [SOLUTION]Okay, from my tests, I've come to these conclusions...
Also take note that... in the App Directory, the export is export const GET = handle(app)
export const POST = handle(app) Whereas in the Pages Directory, the export is export default handle(app) Very easy to miss this difference. Lastly, as a helpful snippet, you can add this to your route to check the runtime app.get("/hello", (c) => {
// Check if running in Node.js
const isNode =
typeof process !== "undefined" &&
process.versions != null &&
process.versions.node != null;
// Log the runtime environment
console.log(`Running in ${isNode ? "Node.js" : "Edge"} environment`);
return c.json({
message: "Hello Next.js!",
});
}); Docs should clarify all of this imo. |
See my comment above for clarification on the docs. It should work with |
@yusukebe how can we add these details to the docs? |
Unable to use hono in nextjs app dir with nodejs runtime
Example Code
Error -
This code has been recreated from the docs https://hono.dev/getting-started/vercel#node-js for the app dir. It works if we set the runtime to
edge
and use thehono/vercel
package like this -The text was updated successfully, but these errors were encountered: