Error cannot file module "@hono/bun" (TS2307)

I'm trying to statically serve some files, in the docs it says to use serveStatic from @hono/bun, but I receive the error modules and its types not found. I've tried multiple solutions but none work: - Tried installing the packaged to ensure @hono/bun was installed using bun add @hono/bun (but it doesnt even exist) - Checked TypeScript types if type declarations existed. Tried adding declare module "@hono/bun"; to global.d.ts to bypass missing types but server doesn't run. - Confirmed Bun version which I'm with the latest version. - Reinstalled dependencies deleting node_modules and bun.lockb, then reinstalling dependencies with bun install, but the error persists. How to solve this?
3 Replies
2t8d0s1p
2t8d0s1p4w ago
you have to use hono/bun not @hono/bun
import { serveStatic } from 'hono/bun'

const app = new Hono()

app.use('/static/*', serveStatic({ root: './' }))
app.use('/favicon.ico', serveStatic({ path: './favicon.ico' }))
app.get('/', (c) => c.text('You can access: /static/hello.txt'))
app.get('*', serveStatic({ path: './static/fallback.txt' }))
import { serveStatic } from 'hono/bun'

const app = new Hono()

app.use('/static/*', serveStatic({ root: './' }))
app.use('/favicon.ico', serveStatic({ path: './favicon.ico' }))
app.get('/', (c) => c.text('You can access: /static/hello.txt'))
app.get('*', serveStatic({ path: './static/fallback.txt' }))
from the docs
Amodeus R.
Amodeus R.OP4w ago
Thanks, that was the problem 🙏
2t8d0s1p
2t8d0s1p4w ago
Happy to help

Did you find this page helpful?