Vercel deployment breaks Notion client authentication while localhost works fine

I’m building a website with Nuxt 3 that connects to Notion using their official client library. The setup works perfectly when I run it locally, but after deploying to Vercel I keep getting this error:

ERROR @notionhq/client error: authentication failed { status: 'unauthorized', description: 'Invalid API token provided.' }

This is confusing because I’m using the exact same NOTION_TOKEN environment variable in both environments. I’ve double-checked that the token is correctly set in my production .env file.

Here’s my current package.json configuration:

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview"
  },
  "devDependencies": {
    "@nuxtjs/supabase": "^0.1.20",
    "@nuxtjs/tailwindcss": "^6.0.1",
    "@tailwindcss/forms": "^0.5.3",
    "@tailwindcss/typography": "^0.5.4",
    "nuxt": "3.1.1",
    "sass": "^1.54.0",
    "sass-loader": "^13.0.2"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^6.2.0",
    "@fortawesome/free-brands-svg-icons": "^6.2.0",
    "@fortawesome/free-regular-svg-icons": "^6.2.0",
    "@fortawesome/free-solid-svg-icons": "^6.2.0",
    "@fortawesome/vue-fontawesome": "^3.0.2",
    "@headlessui/vue": "^1.7.3",
    "@heroicons/vue": "^2.0.12",
    "@notionhq/client": "^2.2.3",
    "highlight.js": "^11.7.0",
    "vue-gtag-next": "^1.14.0"
  }
}

Has anyone dealt with this kind of issue before? The Notion API token works locally but fails in production deployment.

check if your vercel env vars deployed right. they may not sync properly even if you set them. try logging the first few chars of your token in production - ensure it’s there and not undefined or diff from what you see on localhost.

Had the exact same issue with my Next.js/Notion setup on Vercel. The problem’s usually how Vercel handles environment variables. Set your NOTION_TOKEN directly in Vercel’s project dashboard - don’t rely on pushing .env files to the repo. Also double-check how you’re grabbing the token in your server-side code. Nuxt 3 can be weird about env variables between local and production. Drop a console.log in there to see if the token’s actually getting read during your API calls. That unauthorized error typically means the token isn’t reaching the Notion client at all, not that it’s wrong.

This looks like a serverless timeout or environment variable issue, not token auth. I hit the same thing when my Notion calls ran in the wrong context on Vercel’s edge runtime. Initialize your Notion client inside the API route handlers, not at module level. Also check if you’re using the token in server middleware or plugins - Nuxt 3’s server context acts weird on Vercel vs local dev. Wrap your Notion calls in try-catch and log the actual API error response, not just the client wrapper error. The real issue often gets hidden behind that generic unauthorized message.

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