Skip to content

Server Function called from inside createClientOnlyFn results in error "Server function module export not resolved" #5381

Closed

Description

@ulrichstark

Which project does this relate to?

Start

Describe the bug

Calling a server function from inside a createClientOnlyFn triggers following error:

serverFnInfo {
  functionName: 'serverFn_createServerFn_handler',
  importer: [Function: importer]
}
fnModule [Object: null prototype] [Module] { component: [Getter] }
Error: Server function module export not resolved for serverFn ID: src_routes_index_tsx--serverFn_createServerFn_handler
export const Route = createFileRoute("/")({
    component: Home,
});

const serverFn = createServerFn().handler(() => {
    console.log("Hello");
});

const clientFn = createClientOnlyFn(() => {
    serverFn();
});

function Home() {
    return <button onClick={() => clientFn()}>Hello</button>;
}

Your Example Website or App

https://github.com/ulrichstark/tanstack-start-server-fn-export-not-resolved

Steps to Reproduce the Bug or Issue

  1. Clone https://github.com/ulrichstark/tanstack-start-server-fn-export-not-resolved
  2. npm run dev
  3. click the button

Expected behavior

I expect to see "Hello" in terminal of server because I expect that I can call server functions from functions that are only available on the client.

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.132.41
  • OS: macOS
  • Browser: Chrome

Additional context

Removing the wrapping createClientOnlyFn of clientFn fixes the issue.

Activity

  1. schiller-manuel commented on Oct 6, 2025

    @schiller-manuel
    Collaborator

    root cause here is order of compilation, we first apply createClientOnlyFn which removes the reference to serverFn on the server and then dead code elimination kicks in.
    we need to rearrange the compiler plugins to make this work

  2. manish-baghel commented on Oct 12, 2025

    @manish-baghel

    @schiller-manuel
    Is there any workaround for now?

    In my case it was mainly happening due to tanstack-devtool vite plugin. Someone else also reported it TanStack/devtools#209

  3. schiller-manuel commented on Oct 12, 2025

    @schiller-manuel
    Collaborator

    @manish-baghel this is a different issue IMO, not related to this one here. are you using createClientOnlyFn?

  4. added a commit that references this issue on Dec 20, 2025
    09aef82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions