#Mark package as external when deploying with Vercel

6 messages · Page 1 of 1 (latest)

gritty palm
#

I'm trying to deploy a TanStack Start app on Vercel and I've followed the guide to deploy on these platforms but I've ran into a problem where it asks me to mark some Convex components as external from the bundle, which I did following what better-auth+convex docs suggest, but no success.

// vite.config.ts
export default defineConfig({
  ssr: {
    noExternal: [
      "@convex-dev/r2",
      "@convex-dev/twilio",
      "@convex-dev/aggregate",
      "@convex-dev/presence",
      "@convex-dev/rate-limiter",
    ],
  },
  plugins: [
    devtools(),
    nitro({
      vercel: {
        functions: {
          runtime: "bun1.x",
        },
      },
    }),
    // this is the plugin that enables path aliases
    viteTsConfigPaths({
      projects: ["./tsconfig.json"],
    }),
    tailwindcss(),
    tanstackStart(),
    viteReact({
      babel: {
        plugins: ["babel-plugin-react-compiler"],
      },
    }),
  ],
});
// package.json
{
  "dev:web": "bun --bun vite dev --host --port 3000",
  "dev:convex": "bunx convex dev",
  "build:web": "bun --bun vite build",
  "build": "bunx convex deploy --cmd 'bun --bun vite build'"
}
knotty sparrowBOT
#

Hi @gritty palm. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

There isn’t anything in the docs that describes marking Convex components as external in Vite; instead, “external packages” is a Convex bundler feature configured in convex.json, not in vite.config.ts or your Vercel build. [External packages]

A few key points from the available info:

  1. Convex external packages are configured in convex.json
    If you need to exclude something from Convex’s own bundling (for Node actions), you do it like this in the project root (next to package.json):

    {
      "$schema": "./node_modules/convex/schemas/convex.schema.json",
      "node": {
        "externalPackages": ["tslib", "@aws-crypto/sha256-js"]
      }
    }
    

    or with "*" to mark all Node‑action deps as external. [External packages]

    This is what was suggested in a similar R2 issue (marking tslib / @aws-crypto/sha256-js as external). [R2 component thread]

  2. Vite ssr.noExternal is for SSR bundling, not Convex bundling
    The Better Auth + TanStack Start guide only uses ssr.noExternal to force Vite to bundle @convex-dev/better-auth during SSR:

    export default defineConfig({
      ssr: {
        noExternal: ['@convex-dev/better-auth'],
      },
    });
    

    [TanStack Start install; 0.10 migration]

    There’s no guidance in the docs about adding @convex-dev/r2, @convex-dev/twilio, etc. to noExternal, and nothing about Vercel requiring those to be external.

#
  1. Vercel deploy command
    For Vercel, the recommended build command is:

    npx convex deploy --cmd 'npm run build'
    

    (or your equivalent bun --bun vite build), with CONVEX_DEPLOY_KEY set in Vercel. [Connecting to Vercel; How it works]

    That command only affects Convex’s own bundling and deploy; it doesn’t change how Vite bundles your frontend.

Because the knowledge sources don’t include the exact error you’re seeing or any docs about marking those specific Convex components as external for Vite/Vercel, I can’t say precisely which package(s) need to be externalized or whether your ssr.noExternal list is helping or hurting.

From what is documented, the next concrete steps that are supported by the docs are:

  1. If the error is from Convex bundling (e.g. “Could not resolve 'tslib'” or similar):

    • Add a convex.json with node.externalPackages for the offending packages (e.g. tslib, @aws-crypto/sha256-js, etc.), as in the R2 thread. [R2 component thread; External packages]
    • Restart convex dev locally and re‑deploy via your Vercel build command.
  2. If the error is from Vite SSR bundling:

#
  • The only documented noExternal requirement is for @convex-dev/better-auth. [TanStack Start install; 0.10 migration]
    • The docs don’t say to add the other Convex components there, so if adding them is causing issues, you may want to remove them and only keep @convex-dev/better-auth in noExternal.

Given the lack of an exact error message in the sources, I can’t provide a more specific fix. If you can share the precise build/runtime error text, that would determine whether it’s a Convex bundling issue (fix via convex.json) or a Vite SSR issue (fix via ssr.noExternal).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@gritty palm Kapa.ai is still learning and improving, please let me know how I did by reacting below.