Skip to content

Tanstack Start prerender broken with Nitro v3 on Vercel #3905

Description

@josippapez

Environment

Both nitro v3 and v2.
Node v24.12.0

Reproduction

Here's the reproducible:
https://github.com/josippapez/tanstack-vercel-reproducible

Describe the bug

I get the following error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/my-app/.output/server/server.js' imported from /my-app/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_rea_8f07dd2dc4f2e030cbea330a30ef30f3/node_modules/@tanstack/start-plugin-core/dist/esm/preview-server-plugin/plugin.js
    at finalizeResolution (node:internal/modules/esm/resolve:274:11)
    at moduleResolve (node:internal/modules/esm/resolve:864:10)
    at defaultResolve (node:internal/modules/esm/resolve:990:11)
    at nextResolve (node:internal/modules/esm/hooks:785:28)
    at o (file:///my-app/node_modules/.pnpm/@[email protected]/node_modules/@tailwindcss/node/dist/esm-cache.loader.mjs:1:69)
    at nextResolve (node:internal/modules/esm/hooks:785:28)
    at AsyncLoaderHooksOnLoaderHookWorker.resolve (node:internal/modules/esm/hooks:271:30)
    at MessagePort.handleMessage (node:internal/modules/esm/worker:251:24)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:845:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)

For this vite.config.ts

import { defineConfig } from 'vite';
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
import viteReact from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
import tailwindcss from '@tailwindcss/vite';
import { nitro } from 'nitro/vite';

const config = defineConfig({
  build: {
    sourcemap: true,
    outDir: '.output',
    emptyOutDir: true,
    target: 'es2022',
    minify: true,
    rollupOptions: {
      treeshake: true,
      output: {
        manualChunks: (id: string) => {
          if (
            id.includes('phone/dist') ||
            id.includes('react-phone-number-input')
          ) {
            return 'phone';
          }

          if (id.includes('lodash')) {
            return 'lodash';
          }

          if (id.includes('country-flag-icons')) {
            return 'country-flag-icons';
          }

          if (id.includes('medusa')) {
            return 'medusa';
          }
        },
      },
    },
  },
  plugins: [
    // this is the plugin that enables path aliases
    viteTsConfigPaths({
      projects: ['./tsconfig.json'],
    }),
    tailwindcss(),
    tanstackStart(),
    nitro({
      preset: 'vercel',
      output: {
        dir: '.output',
        serverDir: '.output/server',
        publicDir: '.output/static',
      },
      routeRules: {
        // Cache fonts for 1 year (immutable)
        '/fonts/**': {
          headers: {
            'Cache-Control': 'public, max-age=31536000, immutable',
          },
        },
        // Cache images for 1 month
        '/**/*.{jpg,jpeg,png,gif,webp,svg,ico}': {
          headers: {
            'Cache-Control': 'public, max-age=2592000',
          },
        },
        // cache css
        '/**/*.{css}': {
          headers: {
            'Cache-Control': 'public, max-age=604800',
          },
        },
      },
    }),
    viteReact(),
  ],
  resolve: {
    alias: {
      '/fonts': '/public/fonts',
    },
  },
  ssr: {
    noExternal: ['@radix-ui/*', '@medusajs/*', 'nuqs'],
  },
});

export default config;

I did try invoking server.js/index.mjs directly with pnpm serve and node .output/server/index.mjs.

and then i try to pnpm dev (works), pnpm build passes and then pnpm preview and node index.mjs directly, and the node one doesn't start while the preview returns the same error as above

Additional context

No response

Logs

Activity

  1. added
    pending triage
    on Dec 30, 2025
  2. pi0 commented on Dec 30, 2025

    @pi0
    Member

    Have you tried removing output config? setting it manually can break deployment.

    (PS: There is no supported nitro v2 vite plugin (for tanstack start) only nitro v3.)

  3. agustinusnathaniel commented on Jan 2, 2026

    @agustinusnathaniel

    Also reproduced on my side
    Deploying tanstack start app to vercel with prerendering on latest tanstack start and latest nitro-nightly

    Using nitro v3

    Here's my package.json:

    {
      ...,
      "dependencies": {
        ...,
        "@tanstack/react-router": "1.144.0",
        "@tanstack/react-start": "1.145.3",
        ...
      },
      "devDependencies": {
        ...,
        "nitro": "npm:[email protected]",
        ...
      }
    }

    Here's my vite.config.ts:

    import { ValidateEnv } from '@julr/vite-plugin-validate-env';
    import tailwindcss from '@tailwindcss/vite';
    import { tanstackStart } from '@tanstack/react-start/plugin/vite';
    import viteReact from '@vitejs/plugin-react';
    import { nitro } from 'nitro/vite';
    import { defineConfig } from 'vite';
    import tsConfigPaths from 'vite-tsconfig-paths';
    
    export default defineConfig(({ mode }) => {
      return {
        plugins: [
          ValidateEnv(),
          nitro(),
          tanstackStart({
            prerender: {
              enabled: true,
            },
          }),
          viteReact(),
          tailwindcss(),
          tsConfigPaths(),
        ],
        server: {
          open: true,
        },
      };
    });

    Then during build there's this error:

    Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/vercel/path0/dist/server/server.js' imported from /vercel/path0/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_rea_c707235fe1fd544c0836fd0b2566205c/node_modules/@tanstack/start-plugin-core/dist/esm/preview-server-plugin/plugin.js
        at finalizeResolution (node:internal/modules/esm/resolve:274:11)
        at moduleResolve (node:internal/modules/esm/resolve:864:10)
        at defaultResolve (node:internal/modules/esm/resolve:990:11)
        at nextResolve (node:internal/modules/esm/hooks:785:28)
        at o (file:///vercel/path0/node_modules/.pnpm/@[email protected]/node_modules/@tailwindcss/node/dist/esm-cache.loader.mjs:1:69)
        at nextResolve (node:internal/modules/esm/hooks:785:28)
        at AsyncLoaderHooksOnLoaderHookWorker.resolve (node:internal/modules/esm/hooks:269:30)
        at MessagePort.handleMessage (node:internal/modules/esm/worker:251:24)
        at [nodejs.internal.kHybridDispatch] (node:internal/event_target:845:20)
        at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)
  4. josippapez commented on Jan 5, 2026

    @josippapez
    Author

    Have you tried removing output config? setting it manually can break deployment.

    (PS: There is no supported nitro v2 vite plugin (for tanstack start) only nitro v3.)

    Sorry, the missing notifications feature on github is killing me...
    Yes, i did, i did try with:

    nitro({
          preset: 'vercel',
          routeRules: {
            // Cache fonts for 1 year (immutable)
            '/fonts/**': {
              headers: {
                'Cache-Control': 'public, max-age=31536000, immutable',
              },
            },
            // Cache images for 1 month
            '/**/*.{jpg,jpeg,png,gif,webp,svg,ico}': {
              headers: {
                'Cache-Control': 'public, max-age=2592000',
              },
            },
            // cache css
            '/**/*.{css}': {
              headers: {
                'Cache-Control': 'public, max-age=604800',
              },
            },
          },
        }),

    and it didn't fix anything, also, even without routeRules it's still the same (only gaving preset in the nitro)

  5. pi0 commented on Jan 5, 2026

    @pi0
    Member

    Please provide a minimal reproduction. (also try latest tss and nitro nightly, tss prerender started to break at somepoint)

  6. EthanShoeDev commented on Jan 5, 2026

    @EthanShoeDev

    Was also hitting this bug. I got opus 4.5 to use bun patch and it eventually worked with this.

    [email protected]

    FYI - Not expecting this to be upstreamed. Just wanted to add it as reference.

  7. pi0 commented on Jan 5, 2026

    @pi0
    Member

    Thanks for ref @EthanShoeDev. #3921 should fix preview command (therefore tss prerendering support) for vercel.

  8. agustinusnathaniel commented on Jan 6, 2026

    @agustinusnathaniel

    Still error during build on vercel with the latest nightly

     > - Date: 1/6/2026, 1:57:02 PM
     > - Nitro Version: 3.0.1-20260106-130706-e20c92d9
     > - Nitro Preset: vercel
    [info] Spawning preview server...
    [info] npx srvx --static ../../static ./functions/__server.func/index.mjs
    npm warn Unknown env config "npm-globalconfig". This will stop working in the next major version of npm.
    npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm.
    npm warn Unknown env config "_jsr-registry". This will stop working in the next major version of npm.
    npm warn Unknown env config "enable-pre-post-scripts". This will stop working in the next major version of npm.
    npm warn Unknown project config "enable-pre-post-scripts". This will stop working in the next major version of npm.
    sh: line 1: srvx: command not found
    [error] [nitro] Preview server exited with code 127
    error during build:
    Error: Failed to start the Vite preview server for prerendering
        at startPreviewServer (file:///vercel/path0/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_rea_429cef09745127f0fb47a14abe9bb1ae/node_modules/@tanstack/start-plugin-core/dist/esm/prerender.js:195:11)
        at async prerender (file:///vercel/path0/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_rea_429cef09745127f0fb47a14abe9bb1ae/node_modules/@tanstack/start-plugin-core/dist/esm/prerender.js:42:25)
        at async postServerBuild (file:///vercel/path0/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_rea_429cef09745127f0fb47a14abe9bb1ae/node_modules/@tanstack/start-plugin-core/dist/esm/post-server-build.js:38:5)
        at async BasicMinimalPluginContext.handler (file:///vercel/path0/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_rea_429cef09745127f0fb47a14abe9bb1ae/node_modules/@tanstack/start-plugin-core/dist/esm/plugin.js:285:11)
        at async Object.buildApp (file:///vercel/path0/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/rolldown-vite/dist/node/chunks/node.js:33201:5)
        at async CAC.<anonymous> (file:///vercel/path0/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/rolldown-vite/dist/node/cli.js:629:3)
     ELIFECYCLE  Command failed with exit code 1.
    Error: Command "pnpm build" exited with 1
    

    Unless I explicitly install srvx to package.json dependencies or devDependencies and then its successful or able to run.

    Is this expected?

  9. reopened this on Jan 6, 2026
  10. changed the title [-]Vercel preset on both v2 and v3 nitro not working in Tanstack Start[/-] [+] Tanstack Start prerender broken with Nitro v3[/+] on Jan 6, 2026
  11. changed the title [-] Tanstack Start prerender broken with Nitro v3[/-] [+] Tanstack Start prerender broken with Nitro v3 on Vercel[/+] on Jan 6, 2026
  12. added
    bug
    and removed
    pending triage
    on Jan 6, 2026
  13. 2 remaining items

  14. josippapez commented on Jan 7, 2026

    @josippapez
    Author

    @pi0 For me, after bumping to the latest nightly, it started to work... At least, i was able to run the vite preview now and it would start a local production build and i was able to deploy it to vercel. I will probably encounter some problems but it's a start

  15. Zefty commented on Jan 7, 2026

    @Zefty

    Hi team, i've run into similar issues. Using latest nightly version of nitro and TSS but getting this error with pg even though I have the dependency installed

    ReferenceError: Cannot access 'pg' before initialization
        at get default (file:///Users/pengi/Dev/pengwu/.vercel/output/functions/__server.func/_libs/pg.mjs:37:5)
        ... 4 lines matching cause stack trace ...
        at async Array.<anonymous> (file:///Users/pengi/Dev/pengwu/node_modules/.pnpm/[email protected]/node_modules/srvx/dist/log.mjs:12:15) {
      cause: ReferenceError: Cannot access 'pg' before initialization
          at get default (file:///Users/pengi/Dev/pengwu/.vercel/output/functions/__server.func/_libs/pg.mjs:37:5)
          at getAugmentedNamespace (file:///Users/pengi/Dev/pengwu/.vercel/output/functions/__server.func/_libs/pg.mjs:58:13)
          at file:///Users/pengi/Dev/pengwu/.vercel/output/functions/__server.func/_libs/pg.mjs:1931:36
          at ModuleJob.run (node:internal/modules/esm/module_job:377:25)
          at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:671:26)
          at async Array.<anonymous> (file:///Users/pengi/Dev/pengwu/node_modules/.pnpm/[email protected]/node_modules/srvx/dist/log.mjs:12:15),
      status: 500,
      statusText: undefined,
      headers: undefined,
      data: undefined,
      body: undefined,
      unhandled: true
    }
    [request error] [unhandled] [GET] http://localhost:3000/
     ReferenceError: Cannot access 'pg' before initialization
        at get default (file:///Users/pengi/Dev/pengwu/.vercel/output/functions/__server.func/_libs/pg.mjs:37:5)
        ... 4 lines matching cause stack trace ...
        at async Array.<anonymous> (file:///Users/pengi/Dev/pengwu/node_modules/.pnpm/[email protected]/node_modules/srvx/dist/log.mjs:12:15) {
      cause: ReferenceError: Cannot access 'pg' before initialization
          at get default (file:///Users/pengi/Dev/pengwu/.vercel/output/functions/__server.func/_libs/pg.mjs:37:5)
          at getAugmentedNamespace (file:///Users/pengi/Dev/pengwu/.vercel/output/functions/__server.func/_libs/pg.mjs:58:13)
          at file:///Users/pengi/Dev/pengwu/.vercel/output/functions/__server.func/_libs/pg.mjs:1931:36
          at ModuleJob.run (node:internal/modules/esm/module_job:377:25)
          at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:671:26)
          at async Array.<anonymous> (file:///Users/pengi/Dev/pengwu/node_modules/.pnpm/[email protected]/node_modules/srvx/dist/log.mjs:12:15),
      status: 500,
      statusText: undefined,
      headers: undefined,
      data: undefined,
      body: undefined,
      unhandled: true
    }
    

    EIDT: my config

    import { defineConfig } from "vite";
    import { devtools } from "@tanstack/devtools-vite";
    import { tanstackStart } from "@tanstack/react-start/plugin/vite";
    import viteReact from "@vitejs/plugin-react";
    import viteTsConfigPaths from "vite-tsconfig-paths";
    import tailwindcss from "@tailwindcss/vite";
    import { nitro } from "nitro/vite";
    
    const config = defineConfig({
      plugins: [
        devtools(),
        nitro(
          {
            preset: "vercel"
          }
        ),
        // this is the plugin that enables path aliases
        viteTsConfigPaths({
          projects: ["./tsconfig.json"],
        }),
        tailwindcss(),
        tanstackStart({
          router: {
            entry: "./routing/router.tsx",
            routesDirectory: "./routing/routes",
            generatedRouteTree: "./routing/routeTree.gen.ts",
          },
        }),
        viteReact({
          babel: {
            plugins: ["babel-plugin-react-compiler"],
          },
        }),
      ],
    });
    
    export default config;
    
    
  16. fuma-nama commented on Jan 29, 2026

    @fuma-nama

    I suspect there is changes to the behaviour of srvx or nitro, the way Nitro closes the preview server will cause the build process to end with code 143 (which is a fail signal).

    Tried on npm:[email protected], and 3.0.1-alpha.2.

     ╭───────────────── [Build Info] ────────────────────╮
     │                                                   │
     │  - Build Directory: .vercel/output                │
     │  - Date: 1/29/2026, 10:13:19 PM                   │
     │  - Nitro Version: 3.0.1-20260128-211656-ae83c97e  │
     │  - Nitro Preset: vercel                           │
     │                                                   │
     ╰───────────────────────────────────────────────────╯
    
    ℹ Spawning preview server...                                                                                                                                                                                                                                    10:13:19 PM
    ℹ npx srvx --static ../../static ./functions/__server.func/index.mjs                                                                                                                                                                                            10:13:19 PM
    
    (node:28426) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
    (Use `node --trace-warnings ...` to show where the warning was created)
    ➜ Listening on: http://localhost:51022/ (all interfaces)
    λ Server handler: ./functions/__server.func/index.mjs
    ∘ Static files:   ./static/
    [prerender] Concurrency: 12
    [prerender] Crawling: /
    [prerender] Crawling: /docs
    [10:13:19 PM] GET http://localhost:3000/ [200] (67.67ms)
    [10:13:19 PM] GET http://localhost:3000/docs/ [307] (0.81ms)
    [10:13:19 PM] GET http://localhost:3000/docs [200] (14.96ms)
    [prerender] Crawling: /docs/test
    [10:13:19 PM] GET http://localhost:3000/docs/test/ [307] (0.72ms)
    [10:13:19 PM] GET http://localhost:3000/docs/test [200] (6.41ms)
    [prerender] Prerendered 3 pages:
    [prerender] - /
    [prerender] - /docs
    [prerender] - /docs/test
    
    Shutting down server in 3s... (press Ctrl+C again to force close) Server closed.
    
     ERROR  [nitro] Preview server exited with code 143
    

    It is pretty minimal:

    import react from '@vitejs/plugin-react';
    import { tanstackStart } from '@tanstack/react-start/plugin/vite';
    import { defineConfig } from 'vite';
    import tsConfigPaths from 'vite-tsconfig-paths';
    import tailwindcss from '@tailwindcss/vite';
    import { nitro } from 'nitro/vite';
    
    export default defineConfig({
      server: {
        port: 3000,
      },
      plugins: [
        tailwindcss(),
        tsConfigPaths({
          projects: ['./tsconfig.json'],
        }),
        tanstackStart({
          prerender: {
            enabled: true,
          },
        }),
        react(),
        nitro({
          preset: 'vercel',
          vercel: {
            entryFormat: 'node',
          },
        }),
      ],
    });
  17. pi0 commented on Jan 29, 2026

    @pi0
    Member

    might be relavant to #3907 (/cc @schiller-manuel) @fuma-nama please consider a runnable reproduiction it makes it easier for us to investigate 🙏🏼

  18. fuma-nama commented on Jan 29, 2026

    @fuma-nama

    Yep it is currently in my monorepo, will look into it and make a separate reproduction tomorrow.

  19. fuma-nama commented on Jan 30, 2026

    @fuma-nama
  20. added theissue type on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpreset:vercel

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions