question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use 'in' operator to search for 'Symbol(h3ParsedBody)' in undefined Vercel serveless function

See original GitHub issue

Environment


  • Operating System: Windows_NT
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.12
  • Nitro Version: 0.6.0
  • Package Manager: unknown
  • Builder: vite
  • User Config: ssr, runtimeConfig, modules, strapi, vite, css, build, serverHandlers
  • Runtime Modules: @pinia/nuxt@0.4.3, @nuxtjs/strapi@1.6.1
  • Build Modules: -

Reproduction

Reproduction: https://github.com/marcorodriguesdev/nuxt-app

Steps to reproduce:

  • Deploy repo to Vercel using the env variable: NITRO_PRESET=vercel-edge;
  • Do a simple form submit;
  • Check Vercel Functions realtime logs and you will see the error “Cannot use ‘in’ operator to search for ‘Symbol(h3ParsedBody)’ in undefined”

Describe the bug

When deploying a Nuxt 3 app on Vercel, with a serverless function to simply read the body (contact form data) of the Post request, I’m getting the following error on Vercel Realtime Logs: "[POST] /api/contact

TypeError: Cannot use ‘in’ operator to search for ‘Symbol(h3ParsedBody)’ in undefined at readBody (/var/task/node_modules/h3/dist/index.cjs:180:24) at /var/task/api/contact.js:58:24 at Server.<anonymous> (/var/task/___vc/__helpers.js:813:19) at Server.emit (node:events:527:28) at parserOnIncoming (node:_http_server:956:12) at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17) 2022-10-20T19:23:57.162Z 39ca0d68-7c70-4256-8234-076f35415a2d Task timed out after 10.01 seconds"

This is the code that it runs:

export default defineEventHandler(async (event) => {
  try {
    const body = await readBody(event);

    return {
      body,
    };
  } catch (err) {
    console.log(err);
  }
});

Additional context

Code works fine locally. Vercel env variable is set to NITRO_PRESET=vercel-edge

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
danielroecommented, Nov 8, 2022

This is now working fine for me on vercel-edge. Note that you should not use a top-level api/ folder which will be handled outside the nitro server. Instead, place any api routes in ~/server/api.

1reaction
PMLS3commented, Nov 8, 2022

any solution to this? error: “Cannot use ‘in’ operator to search for ‘Symbol(h3ParsedBody)’ in undefined”

Okay, found my error… readBody use event and not event.req

const body = await readBody(event)

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found