Skip to content

Conversation

Copy link

Copilot AI commented Dec 20, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original prompt

This section details on the original issue you should resolve

<issue_title>ReferenceError: Cannot access 'vite_ssr_import_2' before initialization</issue_title>
<issue_description>### Which project does this relate to?

Start

Describe the bug

When starting our tanstack start application in development environment, we sometimes get the following error in the terminal:

ReferenceError: Cannot access '__vite_ssr_import_2__' before initialization
    at Module.getRouter (/Users/ulrichstark/Desktop/tanstack-vite-cannot-access-vite-ssr-import-before-initalization/src/router.tsx:7:9)
    ... 2 lines matching cause stack trace ...
    at async eval (/Users/ulrichstark/Desktop/tanstack-vite-cannot-access-vite-ssr-import-before-initalization/node_modules/@tanstack/start-server-core/src/createStartHandler.ts:243:32) {
  cause: ReferenceError: Cannot access '__vite_ssr_import_2__' before initialization
      at Module.getRouter (/Users/ulrichstark/Desktop/tanstack-vite-cannot-access-vite-ssr-import-before-initalization/src/router.tsx:7:9)
      at getRouter (/Users/ulrichstark/Desktop/tanstack-vite-cannot-access-vite-ssr-import-before-initalization/node_modules/@tanstack/start-server-core/src/createStartHandler.ts:123:55)
      at async handleServerRoutes (/Users/ulrichstark/Desktop/tanstack-vite-cannot-access-vite-ssr-import-before-initalization/node_modules/@tanstack/start-server-core/src/createStartHandler.ts:358:18)
      at async eval (/Users/ulrichstark/Desktop/tanstack-vite-cannot-access-vite-ssr-import-before-initalization/node_modules/@tanstack/start-server-core/src/createStartHandler.ts:243:32),
  status: 500,
  statusText: undefined,
  headers: undefined,
  data: undefined,
  body: undefined,
  unhandled: true
}

And the opened application in the browser only shows:

{"status":500,"unhandled":true,"message":"HTTPError"}

When reloading the page, the error goes away and our application is shown.

Your Example Website or App

https://github.com/ulrichstark/tanstack-vite-cannot-access-vite-ssr-import-before-initalization

Steps to Reproduce the Bug or Issue

  1. Clone https://github.com/ulrichstark/tanstack-vite-cannot-access-vite-ssr-import-before-initalization
  2. Go into folder
  3. npm install
  4. Run npx vite --force
  5. Wait a few seconds
  6. If error isn't visible, stop vite and try again starting from step 4

Expected behavior

No error

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.133.34
  • OS: macOS
  • Browser: Chrome
  • Browser Version: 141.0.7390.123
  • Bundler: Vite
  • Bundler Version: 7.1.12

Additional context

Don't mind the funky reproduction project. It's a product of hours deleting stuff in our project to condense it down to the minimal amount of code that triggers this issue. I hope you can reproduce it on your side. I'm not sure what is causing the issue because it seems to be gone when I delete more relevant code from the project. It's most probably something with my ErrorComponent and its server function which is used as defaultErrorComponent:

import { createServerFn } from "@tanstack/react-start";
import { useEffect } from "react";
import { getCookies } from "@tanstack/react-start/server";
import { House } from "lucide-react";

const reportErrorToServer = createServerFn().handler(() => {
    getCookies();
});

export function ErrorComponent() {
    useEffect(() => {
        reportErrorToServer();
    }, []);

    return <House />;
}
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@schiller-manuel</author><body>
@flodaniel  @kopdigitaal  do you only have this issue once or does it persist?</body></comment_new>
<comment_new><author>@schiller-manuel</author><body>
> whenever we start the project initially

what does this mean? only the first time you run the vite dev server after cloning the repo?</body></comment_new>
<comment_new><author>@schiller-manuel</author><body>
@flodaniel would you be able to provide a reproducer for this? the above reproducer only shows this once </body></comment_new>
<comment_new><author>@schiller-manuel</author><body>
@mackattack3k can you show this in a reproducer project? </body></comment_new>
<comment_new><author>@schiller-manuel</author><body>
@moncapitaine  can you share a complete project that reproduces this?</body></comment_new>
<comment_new><author>@schiller-manuel</author><body>
@amserra can you share a complete project that reproduces this?</body></comment_new>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 20, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@schiller-manuel
Copy link
Contributor

@copilot retry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReferenceError: Cannot access '__vite_ssr_import_2__' before initialization

2 participants