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

The simplest hono app fails to start #17568

Closed
isnifer opened this issue Feb 22, 2025 · 6 comments · Fixed by #17572
Closed

The simplest hono app fails to start #17568

isnifer opened this issue Feb 22, 2025 · 6 comments · Fixed by #17572
Labels
bug Something isn't working needs triage

Comments

@isnifer
Copy link

isnifer commented Feb 22, 2025

What version of Bun is running?

1.2.3+8c4d3ff80

What platform is your computer?

Darwin 24.3.0 arm64 arm

What steps can reproduce the bug?

  1. bun init -y
  2. bun add hono
  3. Create next script:
import { Hono } from 'hono'

const hono = new Hono()

  /**
   * Default route
   */
  .get('/', c => c.json({ message: 'Hello World' }))

export default hono

What is the expected behavior?

It runs

What do you see instead?

❯ bun run server/test_bun_1.2.3.ts
 7 |       if (typeof entryNamespace?.default?.fetch === 'function')  {
 8 |         const server = Bun.serve(entryNamespace.default);
 9 |         console.debug(`Started ${server.development ? 'development ' : ''}server: ${server.protocol}://${server.hostname}:${server.port}`);
10 |       }
11 |    }, reportError);
12 |    const server = Bun.serve(entryNamespace.default);
               ^
TypeError: Invalid route "0". Path must start with '/'
 code: "ERR_INVALID_ARG_TYPE"

      at bun:main:12:28

Bun v1.2.3 (macOS arm64)

Additional information

No response

@isnifer isnifer added bug Something isn't working needs triage labels Feb 22, 2025
@kravetsone
Copy link

kravetsone commented Feb 22, 2025

What version of Bun is running?

1.2.3+8c4d3ff80

What platform is your computer?

Darwin 24.3.0 arm64 arm

What steps can reproduce the bug?

  1. bun init -y
  2. bun add hono
  3. Create next script:

import { Hono } from 'hono'

const hono = new Hono()

/**

  • Default route
    */
    .get('/', c => c.json({ message: 'Hello World' }))

export default hono

What is the expected behavior?

It runs

What do you see instead?

❯ bun run server/test_bun_1.2.3.ts
7 | if (typeof entryNamespace?.default?.fetch === 'function') {
8 | const server = Bun.serve(entryNamespace.default);
9 | console.debug(Started ${server.development ? 'development ' : ''}server: ${server.protocol}://${server.hostname}:${server.port});
10 | }
11 | }, reportError);
12 | const server = Bun.serve(entryNamespace.default);
^
TypeError: Invalid route "0". Path must start with '/'
code: "ERR_INVALID_ARG_TYPE"

  at bun:main:12:28

Bun v1.2.3 (macOS arm64)

Additional information

No response

import { Hono } from 'hono'

const hono = new Hono()

  /**
   * Default route
   */
  .get('/', c => c.json({ message: 'Hello World' }))

export default { 
  port: 3000, 
  fetch: hono.fetch, 
} 

use this as workaround

@stefanos82
Copy link

I came to report the same thing; with the latest update it breaks like crazy!

This simple code

import { Hono } from 'hono'

type Variables = {
    message: string
};

const app = new Hono<{ Variables: Variables }>()

app.use(async (c, next) => {
    c.set('message', 'Hono is cool!');
    await next();
});

app.get('/', (c) => {
    const message = c.get('message');
    return c.text(`The message is "${message}"`)
});

export default app

throws the following errors:

 7 |       if (typeof entryNamespace?.default?.fetch === 'function')  {
 8 |         const server = Bun.serve(entryNamespace.default);
 9 |         console.debug(`Started ${server.development ? 'development ' : ''}server: ${server.protocol}://${server.hostname}:${server.port}`);
10 |       }
11 |    }, reportError);
12 |    const server = Bun.serve(entryNamespace.default);
               ^
TypeError: Invalid route "0". Path must start with '/'
 code: "ERR_INVALID_ARG_TYPE"

      at bun:main:12:28

Bun v1.2.3 (Linux x64)

@kbrgl
Copy link
Contributor

kbrgl commented Feb 22, 2025

Best I can tell, this bug was introduced in #17357.

@kravetsone
Copy link

Best way to avoid export default like this

@nullmastermind
Copy link

Same here, I don't wanna migrate all my projects to export either. 😩

@cstoneham
Copy link

Seems like the latest version isn't released yet, I worked around this by just downgrading:

RUN curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.2"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants