Skip to content
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

nextjs app router + nodejs not working #2466

Open
rengechan opened this issue Apr 4, 2024 · 3 comments
Open

nextjs app router + nodejs not working #2466

rengechan opened this issue Apr 4, 2024 · 3 comments
Labels

Comments

@rengechan
Copy link

What version of Hono are you using?

4.2.1

What runtime/platform is your app running on?

nodejs

What steps can reproduce the bug?

    "next": "14.1.4",
    "@hono/node-server": "^1.9.1",
    "hono": "^4.2.1",

src\app\api\[[...route]]\route.ts

import { Hono } from 'hono';
import { handle } from '@hono/node-server/vercel';

const app = new Hono().basePath('/api');

app.get('/hello', (c) => {
  return c.json({
    message: 'Hello from Hono!',
  });
});

// export const GET = handle(app);
export default handle(app);

with
export const GET = handle(app);

error

 ⨯ TypeError: outgoing.on is not a function
    at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/@hono+node-server@1.9.1/node_modules/@hono/node-server/dist/vercel.mjs:364:14)

with default export
export default handle(app);

error

Failed to find Response internal state key
 ⨯ Detected default export in 'F:\code\xxxx\src\app\api\[[...route]]\route.ts'. Export a named export for each HTTP method instead.
 ⨯ No HTTP methods exported in 'F:\code\xxxx\src\app\api\[[...route]]\route.ts'. Export a named export for each HTTP method.

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

@rengechan rengechan added the bug label Apr 4, 2024
@yusukebe
Copy link
Member

yusukebe commented Apr 9, 2024

Hi @rengechan

Hmm. I've tried, but I can't reproduce it. Could you share a minimal project to reproduce it?

@alexandrefuente
Copy link

@rengechan, I had the same issue, I was looking for some solution, I have changed the line

import { handle } from '@hono/node-server/vercel';
to
import { handle } from 'hono/vercel';

import { Hono } from 'hono';
import { handle } from 'hono/vercel';

const app = new Hono().basePath('/api');

app.get('/hono/:name', async (c) => {
  return c.json({
    message: 'Just a config of Hono backend side GET!'
  });
})

app.post('/hono', async (c) => {
  return c.json({
    message: 'Just a config of Hono backend side POST!'
  });
})

export const GET = handle(app);
export const POST = handle(app);
export default app as never;

Now it is working, but in the terminal still the message.
Detected default export in '/src/app/api/[...slug]/route.ts'. Export a named export for each HTTP method instead.

@cif
Copy link

cif commented Apr 23, 2024

I'm working on a client and service gateway project using vite-dev-server plugin and ran into this issue, but it only happens when I run the vite dev server in a docker container (my preferred workflow).

To reproduce, you can clone the repo and bring up the dev container with compose:

git clone git@github.com:stabledata/surface.git
cd surface
docker-compose up dev

This outputs:

[+] Running 1/0
 ✔ Container surface-dev-1  Created                                                                             0.0s 
Attaching to surface-dev-1
surface-dev-1  | $ vite
surface-dev-1  | Failed to find Response internal state key
surface-dev-1  | 
surface-dev-1  | ♻️  Generating routes...
surface-dev-1  | ✅ Processed routes in 353ms
surface-dev-1  | 
surface-dev-1  |   VITE v5.2.8  ready in 1039 ms
surface-dev-1  | 
surface-dev-1  |   ➜  Local:   http://localhost:4000/
surface-dev-1  |   ➜  Network: http://172.18.0.2:4000/
surface-dev-1  | Expected a Response object
surface-dev-1  | Expected a Response object

Note the line after the vite command Failed to find Response internal state key. When you view http://localhost:4000 in a browser you see the Bun default page Get started by returning a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object in fetch(request)

Everything works perfectly fine on the local machine when running bun dev.

Not a huge blocker, I prefer to work in docker-compose but saw someone else reported the error and thought since I had an easy repro would post here.

Thanks for all the work on Hono! As a previous express user love the API! ❤️ 🙏 I've been playing with patterns for dependency injection and just found the factory/Env pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants