Cannot use 'in' operator to search for 'Symbol(h3ParsedBody)' in undefined Vercel serveless function
See original GitHub issueEnvironment
- 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:
- Created a year ago
- Comments:6 (1 by maintainers)
This is now working fine for me on
vercel-edge
. Note that you should not use a top-levelapi/
folder which will be handled outside the nitro server. Instead, place any api routes in~/server/api
.Okay, found my error… readBody use event and not event.req
const body = await readBody(event)