Skip to content

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

@ulrichstark

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions