Hello!
I’m facing a very unusual runtime error and I’m hoping for some expert help.
The Problem (TL;DR):
My Node.js project deploys successfully to Vercel. However, when I call any API endpoint that uses the @google/genai
package, the function crashes with a 500 - FUNCTION_INVOCATION_FAILED
error.
The runtime log for that specific function call shows the following error:
Cannot find module '/var/task/node_modules/@google/genai/dist/node/index.cjs'
This indicates that while the build process seems to work, the @google/genai
package is not present in the final serverless function artifact at runtime.
What I Have Already Tried:
I have performed extensive troubleshooting to resolve this, including:
- Confirmed
package.json
:@google/genai
is correctly listed in"dependencies"
. - Created a Fresh Project: The error persists even on a brand-new, minimal project linked to a new GitHub repo to rule out hidden configuration issues.
- “Clean Slate” Reset: I have deleted
node_modules
and lock files, reinstalled, and pushed the new lock file. - Cleared Vercel’s Build Cache: I have redeployed multiple times with the build cache disabled.
- Verified API Key: My
GEMINI_API_KEY
is correct and works perfectly in directcURL
requests to the Google API.
My Core Question:
Why would a dependency that appears to be correctly installed during the build not be available at runtime? I am using standard import
statements, not dynamic ones.
This seems like a platform-level issue with the build output. Any insights or suggestions would be greatly appreciated.
Thank you!