Skip to content

HONO: "message":"Cannot use 'in' operator to search for 'QSTASH_TOKEN' in undefined #91

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

Closed
klclee opened this issue Apr 5, 2025 · 1 comment · Fixed by #92
Closed

Comments

@klclee
Copy link

klclee commented Apr 5, 2025

HI all we are using hono on vercel. Everything in development (using npx @upstash/qstash-cli dev as server) works well. BUt when I try the same setup in perview the following exception is getting thrown:

Belwo the the full print:

{"level":50,"time":1743859535563,"pid":4,"hostname":"169.254.14.73","err":{"type":"TypeError","message":"Cannot use 'in' operator to search for 'QSTASH_TOKEN' in undefined","stack":"TypeError: Cannot use 'in' operator to search for 'QSTASH_TOKEN' in undefined\n at Array.handler (file:///var/task/node_modules/.pnpm/@upstash[email protected][email protected]/node_modules/@upstash/workflow/hono.mjs:19:27)\n at #dispatch (file:///var/task/node_modules/.pnpm/[email protected]/node_modules/hono/dist/hono-base.js:181:38)\n at Hono.fetch (file:///var/task/node_modules/.pnpm/[email protected]/node_modules/hono/dist/hono-base.js:207:26)\n at Object. (file:///var/task/node_modules/.pnpm/[email protected]/node_modules/hono/dist/adapter/vercel/handler.js:3:14)\n at u. [as handlerWeb] (/opt/rust/nodejs.js:16:18418)\n at Object.handler (/opt/rust/nodejs.js:2:13474)\n at /opt/rust/nodejs.js:2:1565\n at Server. (/opt/rust/nodejs.js:2:11070)\n at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n at async Server. (/opt/rust/nodejs.js:16:5739)"},"msg":"Cannot use 'in' operator to search for 'QSTASH_TOKEN' in undefined"}

My endpoint looks like this:

activities.post('/registration', serve(async (context) => {
  const payload = context.requestPayload as RegActivitySchemaType;

  serverLogger.info({ payload }, 'registration activity started');

  regActivitySchema.parse(payload)

  serverLogger.info('registration activity: parsed');
  await context.run("reg-activity", async () => {
    await _addRegisterActivity(
      payload.userPk,
      payload.username,
      payload.name
    )
  })
},
  {
    failureFunction: async ({ failStatus, failResponse, }) => {
      serverLogger.error({ failStatus, failResponse }, 'in upstack: registration activity failed');
    }
  }
))

I have my QSTASH_TOKEN set

Image

@CahidArda
Copy link
Collaborator

Hi there, it looks like context.env field becomes undefined when Hono is used with Vercel. We will look into why this is the case and how it can be addressed.

CahidArda added a commit that referenced this issue Apr 9, 2025
It looks like context.env is only defined in Cloudflare Workers. https://hono.dev/docs/api/context#env

When the serve method from hono is used in vercel, context.env is undefined which causes an error.

Fixed the issue by checking if context.env is defined and falling back to process.env if it isn't.

Fixes: #91
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

Successfully merging a pull request may close this issue.

2 participants