-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Which project does this relate to?
Start
Describe the bug
I'm declaring server functions and non-server functions in the same file. The non-server functions call other functions only meant to be executed on the server (like getCookies of @tanstack/react-start/server). That's okay because these non-server functions are wrapped by server functions outside of this file.
If I have a route that uses one of the server function of this file as loader, the route fails to load because of the other unused but still included non-server function of the imported file.
Error message:
[plugin:vite:import-analysis] Failed to resolve import "tanstack-start-injected-head-scripts:v" from "node_modules/@tanstack/start-server-core/dist/esm/loadVirtualModule.js?v=4239e47c". Does the file exist?
index.tsx route:
import { usedServerFunction } from "../functions";
import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/")({
loader: async () => usedServerFunction(),
component: RouteComponent,
});
function RouteComponent() {
const message = Route.useLoaderData();
return <h1>{message}</h1>;
}functions.tsx file:
import { createServerFn } from "@tanstack/react-start";
import { getCookies } from "@tanstack/react-start/server";
export const usedServerFunction = createServerFn().handler(() => {
return "Hello World!";
});
function unusedFunction() {
getCookies();
}Your Example Website or App
Steps to Reproduce the Bug or Issue
git clone https://github.com/ulrichstark/tanstack-repro-failed-to-resolve-import-tanstack-start-injected-head-scripts
cd tanstack-repro-failed-to-resolve-import-tanstack-start-injected-head-scripts
npm install
npx viteExpected behavior
No error
Screenshots or Videos
Platform
- Router / Start Version: 1.134.3
- OS: macOS
- Browser: Chrome
- Browser Version: 141
- Bundler: Vite
- Bundler Version: 7.1.12
Additional context
The error is gone when removing unusedFunction or commenting out the call to getCookies.
Maybe similar to #5673 and #2783.
Shoshak and simon-v-swyftx
Metadata
Metadata
Assignees
Labels
No labels