felixmosh / bull-board

🎯 Queue background jobs inspector
MIT License
2.36k stars 366 forks source link

Hono 4.6.9: Cannot read private member #errorHandler #843

Closed smoothdvd closed 4 days ago

smoothdvd commented 2 weeks ago
../../node_modules/.pnpm/hono@4.6.9/node_modules/hono/dist/hono-base.js (91:1) @ eval
 ⨯ TypeError: Cannot read private member #errorHandler from an object whose class did not declare it
    at Array.map (<anonymous>)
    at route (webpack:///src/app/bull-board/[[...index]]/route.ts?c746:27:4)
    at (rsc)/./src/app/bull-board/[[...index]]/route.ts (/Users/alexgao/Dev/dms/apps/api/.next/server/app/bull-board/[[...index]]/route.js:405:1)
image

I use hono in nextjs 15 like this

const app = new Hono()

// Create the Express adapter
const serverAdapter = new HonoAdapter(serveStatic)

// Create Bull Board with your queues
createBullBoard({
  queues: [
    new BullMQAdapter(getNewspaperArticleEmbedQueue()),
    new BullMQAdapter(getNewspaperPhotoEmbedQueue()),
  ],
  serverAdapter,
})

// Configure the server adapter
serverAdapter.setBasePath('/bull-board')
app.route('/bull-board', serverAdapter.registerPlugin())

rollback to hono 4.6.8, there is no issue anymore

felixmosh commented 2 weeks ago

Hi, thank you for reporting this issue. There is no official Next.js support, but if you willing to make a PR that solves this issue, I'll more than happy to review it :]

smoothdvd commented 2 weeks ago

Maybe cause by this Hono 4.6.9 update: refactor: use # for private methods to reduce the minified file size by @yusukebe in https://github.com/honojs/hono/pull/3596

stephencoffey commented 2 weeks ago

Not using nextJs, but seeing the same error with 6.3.3 and @hono/node-server. Pinning hono to 4.6.8 fixes the problem. Agree with @smoothdvd that it's likely caused by https://github.com/honojs/hono/pull/3596

felixmosh commented 2 weeks ago

Hi @stephencoffey can you share a small repo that reproduces the issue? Where is the code that tries to touch Hono's private members?

TiBianMod commented 2 weeks ago

the issue is coming from Hono 4.6.9

TiBianMod commented 2 weeks ago

for the moment pin version 4.6.8, and you are ready to go.

stephencoffey commented 1 week ago

Hi @stephencoffey can you share a small repo that reproduces the issue? Where is the code that tries to touch Hono's private members?

Hi @felixmosh - steps to recreate here: https://github.com/stephencoffey/bull-board-issue-843-example

stephencoffey commented 1 week ago

No longer reproducible with hono 4.6.10

smoothdvd commented 1 week ago

@felixmosh Looks like HonoAdapter.ts is not compatible with the latest hono app:

in hono-base.ts, the errorHandler is #errorHandler now.

    app.routes.map((r) => {
      let handler
      if (app.#errorHandler === errorHandler) {
        handler = r.handler
      } else {
        handler = async (c: Context, next: Next) =>
          (await compose<Context>([], app.#errorHandler)(c, () => r.handler(c, next))).res
        ;(handler as any)[COMPOSED_HANDLER] = r.handler
      }

      subApp.#addRoute(r.method, r.path, handler)
    })

https://github.com/honojs/hono/blob/082862bb7d8ee95847fbeeb736eb4e20d4646ee7/src/hono-base.ts#L217C1-L218C1

HonoAdapter.ts

  setErrorHandler(handler: (error: Error) => ControllerHandlerReturnType): this {
    this.errorHandler = handler;
    return this;
  }

This will lead error of "TypeError: Cannot read private member #errorHandler from an object whose class did not declare it" when grouping other HonoAdapter's Hono instance in Honor routes.

app.route('/bull-board', serverAdapter.registerPlugin())
Screenshot 2024-11-14 at 9 16 49 PM Screenshot 2024-11-14 at 9 19 03 PM
felixmosh commented 1 week ago

@smoothdvd please update to Hono 4.6.10 (which solved this issue...)

smoothdvd commented 1 week ago

@felixmosh I already upgrade to Hono 4.6.10.

felixmosh commented 1 week ago

I've just tested it locally, with the example (with-hono), with 4.6.9, it fails, with 4.6.10 it works as expected.

TiBianMod commented 1 week ago

weird stuff....

if you use require works, no issue

const { Hono } = require('hono');

if you use import throws, some issue

import { Hono } from "hono";
Cannot access invalid private field (evaluating 'app.#errorHandler')
felixmosh commented 1 week ago

weird stuff....

if you use require works, no issue

const { Hono } = require('hono');

if you use import throws, some issue

import { Hono } from "hono";
Cannot access invalid private field (evaluating 'app.#errorHandler')

Actually it is not weird, since Node applies the private field validation on ESM only

TiBianMod commented 1 week ago

OK, but this is an issue that we need to solve @felixmosh I think you need to reopen the issue!!!

felixmosh commented 1 week ago

We should use onError instead... Will you open a PR

felixmosh commented 5 days ago

I've tested the code, looks like this is related to Hono, image

When using the pattern of app.route('/', new Hono()), the code above, tries to access a private property of the second Hono instance. which is wrong.

TiBianMod commented 5 days ago

@felixmosh the issue is solved on Hone v4.6.11

PR: https://github.com/honojs/hono/pull/3692 Relase: https://github.com/honojs/hono/releases/tag/v4.6.11

felixmosh commented 4 days ago

Can we close this issue?

yusukebe commented 4 days ago

Sorry for the trouble!