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

TypeError: Cannot read private member #body from an object whose class did not declare it #150

Closed
lawandothman opened this issue Mar 4, 2024 · 5 comments

Comments

@lawandothman
Copy link

lawandothman commented Mar 4, 2024

Since upgrading @hono/node-server to 1.6.0 we are seeing the following error when starting the dev server

VITE v4.5.2  ready in 446 ms
➜  Local:   http://localhost:3002/
➜  Network: http://192.168.1.3:3002/
➜  Network: http://192.168.64.1:3002/
➜  press h to show help
Failed to find Response internal state key
2024-03-03T22:10:25.605Z [info]: Initializing subscription {}
2024-03-03T22:10:25.659Z [info]:   <-- GET / {}
2024-03-03T22:10:25.661Z [info]:   --> GET / 404 2ms {}
/Users/lawand.othman/Developer/node_modules/.pnpm/@hono+node-server@1.8.1/node_modules/@hono/node-server/dist/index.js:213
  return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
                                                            ^

TypeError: Cannot read private member #body from an object whose class did not declare it
     at [getResponseCache] (/Users/lawand.othman/Developer/node_modules/.pnpm/@hono+node-server@1.8.1/node_modules/@hono/node-server/dist/index.js:213:60)
     at getInternalBody (/Users/lawand.othman/Developer/node_modules/.pnpm/@hono+node-server@1.8.1/node_modules/@hono/node-server/dist/index.js:280:42)
     at responseViaResponseObject (/Users/lawand.othman/Developer/node_modules/.pnpm/@hono+node-server@1.8.1/node_modules/@hono/node-server/dist/index.js:354:24)

Node.js v18.17.1
 ELIFECYCLE  Command failed with exit code 1.
ERROR: command finished with error: command (/Users/lawand.othman/Developer/apps/braze-adapter) /Users/lawand.othman/.nvm/versions/node/v18.17.1/bin/pnpm run dev exited (1)
braze-adapter#dev: command (/Users/lawand.othman/Developer/apps/braze-adapter) /Users/lawand.othman/.nvm/versions/node/v18.17.1/bin/pnpm run dev exited (1)

I'm using 'vite-plugin-node@3.1.0' with a custom adapter to run the dev server, here's the relevant vite config part

import { getRequestListener } from '@hono/node-server';


      ...VitePluginNode({
        adapter: async ({ app, req, res }) => {
          getRequestListener((request) => app.fetch(request))(req, res);
        },
        appPath: isProd
          ? {
            /**
             * For production we generate 2 files, so we can load the tracing like
             * "node --import tracing.js main.js". As opentelemetry patches the built-in http/http2
             * modules, this way we can make sure the tracing is loaded before the app loads.
             */
            main: './src/main.ts',
            tracing: './src/init-tracing.ts',
          }
          : './src/dev.ts',
      }),

I suspect this PR is the culprit here #133

@yusukebe
Copy link
Member

yusukebe commented Mar 4, 2024

Hi @lawandothman

I'm using 'vite-plugin-node@3.1.0' with a custom adapter to run the dev server, here's the relevant vite config part

We may be able to fix it, but we cannot support this case because it is not how we expect it to be used.

@lawandothman
Copy link
Author

We may be able to fix it, but we cannot support this case because it is not how we expect it to be used.

Hey @yusukebe

That would be awesome thank you! out of interest how do you expect it to be used with vite?

I had a look through the documentation of vite-plugin-node and hono is not supported there out of the box so I opted to use the custom adapter

@yusukebe
Copy link
Member

yusukebe commented Mar 4, 2024

@lawandothman

Have you ever seen this? https://github.com/honojs/vite-plugins/tree/main/packages/dev-server

We are developing our custom dev-server for Vite using the @hono/node-server.

@lawandothman
Copy link
Author

lawandothman commented Mar 4, 2024

Thanks for the suggestion @yusukebe I did come across that plugin today as I was debugging this issue, I will give it a spin in the meanwhile and see how it goes 🤞

Update: I managed to integrate with @hono/vite-dev-server successfully 🎉

@yusukebe
Copy link
Member

@lawandothman Great! Can we close this issue?

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

No branches or pull requests

2 participants