Skip to content

Type Definition Colocated with createServerFn Causes: Failed to resolve import "tanstack-start-injected-head-scripts:v" #6480

@ryant26

Description

@ryant26

Which project does this relate to?

Router

Describe the bug

I have found an issue which is similar in nature to #5709. It seems that a type definition within the same file as as a Server Function definition can cause the "Failed to resolve import "tanstack-start-injected-head-scripts:v" error".

The problematic type definition is L#11 of the posts.server.ts file in this repo:

export type CreatePostInput = z.infer<typeof postSchema>;

You can see that this type definition infers a typescript type from a Zod schema, that Zod schema uses an enum imported from another file (PostService.ts). PostService imports the server-only function getCookies. Note, the Zod usage isn't important but I included it as an example of how this might occur in a real-world use case.

The reason I logged this issue instead of dismissing it as a duplicate of #5709 is because I think most devs would assume that the type definitions are stripped by Vite and thus this is a very hard to track down bug.

More generally, and perhaps this isn't the right forum to have this discussion, the dead code elimination strategy described by @schiller-manuel feels like the framework is trying to be too clever. This kind of "magic" frequently leads to the kinds of bugs I'm logging here that are extremely difficult to debug. I think the TanStack team should consider an approach which makes the boundaries of server functions more explicit, even at the cost of additional boilerplate or imposed file/directory structures.

Your Example Website or App

https://github.com/ryant26/tss_server_code_leak_repro/tree/master

Steps to Reproduce the Bug or Issue

  1. Clone the repo
  2. $> npm install
  3. $> npm run dev
  4. Navigate to the "Posts" page

Expected behavior

Expectation:
The page loads without error.

Actual:
An error is surfaced by the Router Dev Tools:

[plugin:vite:import-analysis] Failed to resolve import "tanstack-start-injected-head-scripts:v" from "node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js?v=76cc28db". Does the file exist?

Screenshots or Videos

Image

Platform

  • Router / Start Version: 1.154.12
  • OS: Linux
  • Browser: Chrome
  • Browser Version: 143.0.7499.193
  • Bundler: Vite
  • Bundler Version: 7.3.1

Additional context

Thanks to the team for their hard work on TanStack Start, it's an excellent framework

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions