Vercel Function Error: Cannot read 'Context' in @shopify/shopify-api

Hi Vercel Community,

I’m hoping someone can help me with a persistent runtime error on the Hobby plan. My serverless function (api/submit.ts) fails to initialize, and I’m completely stuck after several days of troubleshooting. Any help would be greatly appreciated.

Current Behavior

When the /api/submit endpoint is called, the function crashes instantly.

  • Browser Console: Shows a 500 (Internal Server Error).

  • Vercel Function Log: Shows a fatal error immediately on startup: TypeError: Cannot read properties of undefined (reading 'Context'). This happens when the code tries to run Shopify.Context.initialize(...).

Expected Behavior

The function should initialize the @shopify/shopify-api library, find Shopify.Context, and proceed to run the endpoint logic (moderation, file upload, etc.).

Setup & Troubleshooting Steps Already Taken

Here is a summary of my setup and everything I’ve tried so far:

  1. Dependencies Verified: package.json is correctly set up with @shopify/shopify-api v10.0.0 (and openai, busboy, cors, etc.). Vercel’s build log confirms it installs them.

  2. Environment Variables: All 5 required keys (3 for Shopify, 1 for OpenAI, 1 for Shopify domain) are correctly configured in the Vercel project settings.

  3. Import Methods Tried: We have tried multiple ways to import and initialize the library (require, dynamic import(), various import paths for restResources), but they all result in the same TypeError.

  4. Isolation Test: We deployed a minimal test function with only require('@shopify/shopify-api') and a console.log(Shopify). The Vercel log showed Typeof Shopify: undefined. This confirms the library itself is not loading correctly in the Vercel runtime.

  5. New Project Test: I deployed the exact same codebase and environment variables to a brand new, clean Vercel project (nodejs-serverless-function-express-ten-hazel-19). The exact same initialization error occurred, ruling out a corrupted project state.

  • Project URLs:

    • https://nodejs-serverless-function-express-richs-projects-7a3c1949.vercel.app/

    • https://nodejs-serverless-function-express-ten-hazel-19.vercel.app/

  • Framework: Node.js / Express

  • Environment: Hobby Plan

  • Library: @shopify/shopify-api v10.0.0

Given that the error happens immediately, persists across new projects, and fails even when only requiring the library, this strongly suggests an incompatibility or module-loading issue between the Vercel Node.js runtime and how @shopify/shopify-api v10.0.0 is packaged.

Has anyone else experienced this TypeError: Cannot read properties of undefined (reading 'Context') when using @shopify/shopify-api on Vercel? Is there a known workaround?

Thank you!

If you’re having trouble deploying an Express app, this guide can help.

You can also ask v0 for suggestions tailored to your own project setup.

Hi @rich-9735! :slightly_smiling_face:

We haven’t heard back from you. If you’re still stuck, feel free to share any updates, logs, or additional context that might help us assist you better!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.