Skip to content

createServerFn gets tree-shaken when only called server-side #5976

@Dzinlife

Description

@Dzinlife

Which project does this relate to?

Start

Describe the bug

When a createServerFn is only called from a createFileRoute handler (server-side) and not use in any client-side code, it gets tree-shaken during production build, causing runtime errors.

Reproduction

// src/routes/api.ts
const serverFn = createServerFn({ method: "POST" })
  .handler(async ({ data }) => {
    console.log("This never runs"); // ❌ Never executes
    // ...
  });

export const Route = createFileRoute("/api")({
  server: {
    handlers: {
      POST: async ({ request }) => {
        serverFn(); // ❌ throw 500
        // ...
      },
    },
  },
});

Environment

@tanstack/react-start: ^1.139.8
vite: ^7.1.7
Build target: Production (works fine in dev mode)

Your Example Website or App

//

Steps to Reproduce the Bug or Issue

//

Expected behavior

//

Screenshots or Videos

No response

Platform

//

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions