Skip to content

[Start] v1.143.3 breaks both dev and production - Buffer is not defined + attachRouterServerSsrUtils is not defined #6204

Closed

Description

@Andresuito

Which project does this relate to?

Start

Describe the bug

After upgrading to v1.143.3, TanStack Start has two critical bugs:

1. Development mode: ReferenceError: Buffer is not defined

  • Database client (postgres/pg) is bundled and executed in the browser
  • Occurs even though database is ONLY imported in .server.ts files
  • Error location: node_modules/postgres/src/bytes.js

2. Production mode: ReferenceError: attachRouterServerSsrUtils is not defined

  • Build succeeds but server crashes on startup
  • Error location: .output/server/chunks/_/server-FFq0J1Wz.mjs:594:3
  • Makes production deployment completely broken

Both issues suggest v1.143.3 has broken changes in:

  • Server/client code splitting (dev)
  • SSR utilities bundling (prod)

Your Example Website or App

none

Steps to Reproduce the Bug or Issue

  1. Create a TanStack Start project with database integration

  2. Install dependencies: bun add drizzle-orm postgres

  3. Create database client in src/lib/db/index.ts:

    import { drizzle } from "drizzle-orm/postgres-js";
    import postgres from "postgres";
    
    const connection = postgres(process.env.DATABASE_URL!);
    export const db = drizzle(connection);

Create server function in src/services/users.server.ts:

import { createServerFn } from "@tanstack/react-start";
import { db } from "@/lib/db";

export const getUsers = createServerFn({ method: "GET" })
.handler(async () => {
return await db.query.user.findMany();
});

Update package.json to v1.143.3:

"@tanstack/react-router": "^1.143.3",
"@tanstack/react-router-devtools": "^1.143.3",
"@tanstack/react-router-ssr-query": "^1.143.3",
"@tanstack/react-start": "^1.143.3",
"@tanstack/router-plugin": "^1.143.3"

Open browser at http://localhost:3000/
Check console → Error: ReferenceError: Buffer is not defined at node_modules/postgres/src/bytes.js
Note: Database is ONLY imported in .server.ts files but gets bundled in browser anyway.

Expected behavior

Server-only code (.server.ts files) and their dependencies (like postgres, pg, drizzle-orm) should be completely excluded from the client bundle and never execute in the browser.

Screenshots or Videos

buffer.error.mp4

Platform

  • Router / Start Version: 1.143.3
  • OS: macOS
  • Browser: Chrome
  • Bundler: Vite
  • Database: PostgreSQL with Drizzle ORM
  • Packages affected: Both postgres@3.4.7 and pg@8.x exhibit the same issue

Additional context

No response

Activity

  1. coderabbitai commented on Dec 23, 2025

    @coderabbitai
    Contributor

    📝 CodeRabbit Plan Mode

    Generate an implementation plan and prompts that you can use with your favorite coding agent.

    • Create Plan
    Examples

    🔗 Similar Issues

    Possible Duplicates

    Related Issues

    🔗 Related PRs

    #5215 - fix: various fixes [merged]
    #5284 - tests(start): update spa mode e2e to use production build [merged]
    #5647 - test(solid-start): fix dev server for suspense transition [merged]
    #5896 - fix: memory leaks [merged]
    #5903 - fix(solid-start): fix hydration regression in 1.136.9 [merged]

    👤 Suggested Assignees

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord or schedule a call!

  2. schiller-manuel commented on Dec 23, 2025

    @schiller-manuel
    Collaborator

    please provide a complete example project as a git repo

  3. Andresuito commented on Dec 23, 2025

    @Andresuito
    Author

    It happens to me in this project - Link

  4. schiller-manuel commented on Dec 23, 2025

    @schiller-manuel
    Collaborator

    i cannot get your project to run and to reproduce your error:

    1. git clone
    2. bun i
    3. added a fake .env
    DATABASE_URL=postgres://user:password@localhost:5432/mydatabase
    RESEND_API_KEY=your_resend_api_key_here
    
    1. bun dev

    then i got this error:

     ERROR  Worker error: A provided trusted origin is invalid, make sure your trusted origins list is properly defined.                 10:21:03 PM
    
    
    10:21:03 PM [vite] Internal server error: fetch failed
          at node:internal/deps/undici/undici:13510:13
          at async fetchAddress (file:///private/tmp/real-state/node_modules/nitro/dist/_dev.mjs:77:9)
          at async nitroDevMiddleware (file:///private/tmp/real-state/node_modules/nitro/dist/_build/vite.plugin.mjs:279:19)
    
  5. Andresuito commented on Dec 24, 2025

    @Andresuito
    Author

    Sorry, I had the plugins in the wrong order in vite.config.ts.

  6. joshymcd commented on Dec 24, 2025

    @joshymcd

    @Andresuito whats your correct order? im having the same issue

  7. Andresuito commented on Dec 24, 2025

    @Andresuito
    Author

    @joshymcd This

    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: [
        viteTsConfigPaths({
          projects: ['./tsconfig.json'],
        }),
        tanstackStart(),
        nitro(),
        devtools(),
        tailwindcss(),
        viteReact(),
      ],
    })
    
    export default config
  8. nick-cheatwood7 commented on Dec 24, 2025

    @nick-cheatwood7

    @joshymcd This

    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: [
    viteTsConfigPaths({
    projects: ['./tsconfig.json'],
    }),
    tanstackStart(),
    nitro(),
    devtools(),
    tailwindcss(),
    viteReact(),
    ],
    })

    export default config

    I was facing the exact same issue (with kysely instead of drizzle), and this fixed it for me, too. Thanks!

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions