router icon indicating copy to clipboard operation
router copied to clipboard

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.

Open SeyyedKhandon opened this issue 1 year ago • 1 comments

Which project does this relate to?

Start

Describe the bug

This issue is a follow up for https://github.com/TanStack/router/discussions/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

https://github.com/TanStack/router/discussions/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 avatar Sep 29 '24 19:09 SeyyedKhandon

any progress?

ncor avatar Oct 05 '24 07:10 ncor

Facing this issue for the past 5 days...

mwondhaf avatar Oct 09 '24 07:10 mwondhaf

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)

schiller-manuel avatar Nov 16 '24 22:11 schiller-manuel

It works now. Thanks

SeyyedKhandon avatar Nov 17 '24 18:11 SeyyedKhandon