#process is not defined error when calling server function

24 messages · Page 1 of 1 (latest)

winter sentinel
#

Hello, I am trying to call a dummy server function inside my app context like this:

import testFn from "@/test";

...
const AppContext = createContext<AppContextType | null>(null);

export const AppContextProvider = ({ children }: { children: ReactNode }) => {
  const [userMode, setUserMode] = useState<UserMode | undefined>(undefined);
  const [isMounted, setIsMounted] = useState(false);
  useEffect(() => {
    if (typeof window !== "undefined") {
      const appContextStored = localStorage.getItem(AppContextStorage.STORAGE_KEY);
      if (appContextStored) {
        try {
          const parsed = JSON.parse(appContextStored) as AppContextStorage;
          setUserMode(parsed.userMode);
        } catch (error) {
          testFn();  // CALL SERVER FN
          setUserMode(UserMode.User);
...

test server fn:

import { createServerFn } from "@tanstack/react-start";

const testFn = createServerFn({
  method: "POST",
}).handler(() => {
  console.log("Kepa");
});

export default testFn;

Error:

index.js?v=e1735df9:6 Uncaught (in promise) ReferenceError: process is not defined
    at createClientRpc (index.js?v=e1735df9:6:41)
    at test.tsx:1:55

createClientRpc uses process:

const createClientRpc = (functionId, serverBase) => {
    const sanitizedAppBase = sanitizeBase(process.env.TSS_APP_BASE || "/");

I guess that server code is leaking into my client code 😭 but I dont know the cause

broken wind
#

which version of start are you using?

winter sentinel
#

I have upgraded to 1.132, but now createServerRootRoute no longer exists ☹️ and I don't find any references about it in the docs or in github, what the ...?

zealous phoenix
#

There's brand new breaking changes with the latest release.

winter sentinel
#

Oh dang... thanks for the info, but I am still unable to find anything 😭😭 Why searching for references of createServerRootRoute in github/tanstack docs does not show anything?

zealous phoenix
#

Yeah at this moment, better to wait for everything to roll out...

winter sentinel
#

watching history of the web in real time, what a time to be alive

zealous phoenix
#

oh yes baby

#

That's exactly the docs i was missing lol

winter sentinel
#

Now I can not overcome this issue 😭

TypeError: (intermediate value).routerEntry.getRouter is not a function
    at getRouter (C:\Repos\ResanoRP\node_modules\@tanstack\start-server-core\src\createStartHandler.ts:145:55)
    ... 2 lines matching cause stack trace ...
    at async eval (C:\Repos\ResanoRP\node_modules\@tanstack\start-server-core\src\createStartHandler.ts:263:32) {
  cause: TypeError: (intermediate value).routerEntry.getRouter is not a function
      at getRouter (C:\Repos\ResanoRP\node_modules\@tanstack\start-server-core\src\createStartHandler.ts:145:55)
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
      at async handleServerRoutes (C:\Repos\ResanoRP\node_modules\@tanstack\start-server-core\src\createStartHandler.ts:375:18)
      at async eval (C:\Repos\ResanoRP\node_modules\@tanstack\start-server-core\src\createStartHandler.ts:263:32),
  status: 500,
  statusText: undefined,
  headers: undefined,
  data: undefined,
  body: undefined,
  unhandled: true
}
broken wind
winter sentinel
inner cove
#

@winter sentinel @broken wind If you guys could provide an update on this, recently upgraded from 1.2.23 to 1.2.32 and now my serverFns are showing up on the client ("createClientRpc.js?v=5d579772:9 Uncaught (in promise) ReferenceError: process is not defined") even though all of the docs I have read says that tanstack start splits them automatically

#
export const setTheme = createServerFn({ method: "POST" })
  .inputValidator((data: unknown) => {
    if (typeof data != "string" || (data != "dark" && data != "light")) {
      throw new Error("Invalid theme provided");
    }
    return data as Theme;
  })
  .handler(async ({ data }) => {
    setCookie(storageKey, data);
  });
#

No other errors

wise oar
#

Facing the same exact issue @inner cove did you manage to solve this?
Only happens in dev mode, when building it works fine.

#
createClientRpc.js?v=da92de13:9 Uncaught (in promise) ReferenceError: process is not defined
    at createClientRpc (createClientRpc.js?v=da92de13:9:43)
    at auth.ts:1:55

package.json:

    "@tanstack/react-router": "^1.132.0",
    "@tanstack/react-router-devtools": "^1.132.0",
    "@tanstack/react-start": "^1.132.0",
wise oar
#

noticed it only happens when hmr: false in vite.config.ts, strange...

broken wind
#

same for you @wise oar

inner cove