Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: compiler error on arrow function implicit return in server functions - Invariant failed: createServerFn must be called with a function that is marked with the 'use server' pragma. #2441

Closed
SeyyedKhandon opened this issue Sep 29, 2024 · 4 comments
Labels
bug Something isn't working start Everything about TanStack Start

Comments

@SeyyedKhandon
Copy link

SeyyedKhandon commented Sep 29, 2024

Which project does this relate to?

Start

Describe the bug

This issue is a follow up for #2434 discussion:

This server function:

const getHashId = createServerFn("GET", () => storage.hashId);

results in :

Invariant failed: createServerFn must be called with a function that is marked with the 'use server' pragma. Are you using the @tanstack/router-plugin/vite ?

while it works for:

const getHashId = createServerFn("GET", () => {
  return storage.hashId;
});

Your Example Website or App

#2434

Steps to Reproduce the Bug or Issue

  1. just use an arrow function with implicit return

Expected behavior

As a user I expect it to support javascript syntax correctly, which means it should support any variant of functions that we pass to be considered a fully javascript compatible.

Screenshots or Videos

Image

Platform

  • OS: Macos 15 sequia
  • Browser: Chrome 129.0.6668.60

Additional context

No response

@SeyyedKhandon SeyyedKhandon changed the title Compiler error on arrow function implicit return in server functions - Invariant failed: createServerFn must be called with a function that is marked with the 'use server' pragma. Bug: Compiler error on arrow function implicit return in server functions - Invariant failed: createServerFn must be called with a function that is marked with the 'use server' pragma. Sep 29, 2024
@SeyyedKhandon SeyyedKhandon changed the title Bug: Compiler error on arrow function implicit return in server functions - Invariant failed: createServerFn must be called with a function that is marked with the 'use server' pragma. Bug: compiler error on arrow function implicit return in server functions - Invariant failed: createServerFn must be called with a function that is marked with the 'use server' pragma. Sep 29, 2024
@SeanCassiere SeanCassiere added bug Something isn't working start Everything about TanStack Start labels Sep 30, 2024
@ncor
Copy link

ncor commented Oct 5, 2024

any progress?

@mwondhaf
Copy link

mwondhaf commented Oct 9, 2024

Facing this issue for the past 5 days...

@schiller-manuel
Copy link
Contributor

can you please retest with the latest start version? server functions were updated a lot so this might be fixed (or not, let's find out)

@SeyyedKhandon
Copy link
Author

It works now. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working start Everything about TanStack Start
Projects
None yet
Development

No branches or pull requests

5 participants