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

Invalid handler. It should be a function #92

Closed
edimitchel opened this issue Aug 8, 2023 · 4 comments
Closed

Invalid handler. It should be a function #92

edimitchel opened this issue Aug 8, 2023 · 4 comments

Comments

@edimitchel
Copy link

edimitchel commented Aug 8, 2023

Environment

h3 1.8.0-rc.2 and 1.8.0-rc.3
OSX, with pnpm 8.6

Reproduction

https://stackblitz.com/edit/github-uqdf6b?file=package.json

Describe the bug

The issue occurred when I tried to illustrate a feature request.

When I use listhen since h3 was added with the rc version (the 2nd), I got this following issue:

ERROR Invalid handler. It should be a function:

Code:

app.use(
  '/api',
  eventHandler((event) =>
    proxyRequest(event, join(BACKEND_ENDPOINT, event.path))
  )
);

Additional context

According to the error message, it is linked with fromNodeMiddleware.

Here the trace from the function (in h3):

    at fromNodeMiddleware (file:///Users/micheledighofffer/DEV/listhen/node_modules/.pnpm/h3@1.8.0-rc.3/node_modules/h3/dist/index.mjs:1840:31)
    at loadHandle (file:///Users/micheledighofffer/DEV/listhen/dist/index.mjs:892:26)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async listenAndWatch (file:///Users/micheledighofffer/DEV/listhen/dist/index.mjs:998:3)
    at async Object.run (file:///Users/micheledighofffer/DEV/listhen/dist/cli.mjs:91:7)
    at async runCommand (file:///Users/micheledighofffer/DEV/listhen/node_modules/.pnpm/citty@0.1.2/node_modules/citty/dist/index.mjs:313:5)
    at async runMain (file:///Users/micheledighofffer/DEV/listhen/node_modules/.pnpm/citty@0.1.2/node_modules/citty/dist/index.mjs:425:7)

The function is called by listhen even it's not use in the app.

It seems that the type is not the one expected and doesn't match the change made by @danielroe (7e9570)
The handler type is not function but object.

Logs

No response

Copy link
Member

The issue is that you have not exported a handler function from your app.ts file. Add the following line at the end and you should be fine: export default app

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Aug 8, 2023
@edimitchel
Copy link
Author

Thank you,
Isn't possible to add an hint in console to prevent that kind of issue?

@pi0 pi0 transferred this issue from unjs/h3 Aug 8, 2023
@pi0 pi0 reopened this Aug 8, 2023
@pi0
Copy link
Member

pi0 commented Aug 8, 2023

Transfered to listhen to improve error

@pi0
Copy link
Member

pi0 commented Aug 12, 2023

better error in the next version:

image image

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

3 participants