#[FIXED] Persistent `TypeError: undefined is not an object` in production

17 messages · Page 1 of 1 (latest)

brazen cobalt
#

Hey, I'm encountering a persistent TypeError: undefined is not an object in production, and I’ve ruled out every possible cause.

Astro version: 5.12.4 (also appeared on 5.10.1)
Output: static
Using integrations: <@&1055234544183287879>/react, <@&1055234544183287879>/tailwind, <@&1055234544183287879>/partytown, <@&1055234544183287879>/mdx, <@&1055234544183287879>/sitemap
Using ClientRouter imported from astro:transitions, but removing them doesn't fixed the issue.

✅ What I’ve tried and confirmed:
Clean dist/ via npm run build
Upload to a real web server via FTP
Verified there are no traces of ClientRouter or astro:transitions in source or layout and error persists
Used astro check → no errors
Grepped dist/ for startViewTransition, navigation.entries, etc → still present in JS
Confirmed that even in final dist/, a module script exists that references astro:before-preparation and throws the TypeError on Brave Mobile on iOS but not on desktop, nor on Safari or Firefox or Chrome, connecting iPhone to web devtools doesn't give any information other than the message TypeError: undefined is not an object

⚠️ Problem:
The error appears before any render, even before the page loads.
The stack trace always points to an injected script (likely Astro’s view transitions polyfill or prefetch script).
It breaks only on Brave Mobile, where window.navigation exists but is partially implemented (thus navigation.entries throws).

Is there any way to fix this issue I'm missing? The page on Brave on iOS seems to be trying to load something in an endless loop while you navigate, the page doesn't reload itself, but tries to load something as the loading bar at the bottom randomly appears

Thanks!

sleek beaconBOT
#

Hi @brazen cobalt. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

I'm sorry you're encountering this persistent error. Based on the information in the knowledge sources, here’s what can be determined:

  • Astro’s <ClientRouter /> and its related scripts (including prefetch and view transitions polyfills) are injected when you use view transitions or prefetch features. These scripts may reference browser APIs like window.navigation or startViewTransition for enhanced navigation and animation support View transitions Using with View Transitions.
  • The error you describe—TypeError: undefined is not an object—occurring specifically on Brave Mobile (iOS), and not on other browsers, suggests a compatibility issue with the polyfill or prefetch script that is injected by Astro. You noted that window.navigation exists but is only partially implemented, which matches the scenario where a polyfill or script expects a fully implemented API and fails when accessing properties like navigation.entries.
  • The knowledge sources confirm that prefetching and view transitions scripts are automatically injected when <ClientRouter /> is used, and that prefetching is enabled by default in this mode Prefetch Options Using with View Transitions. However, there is no explicit documentation about handling partial implementations of browser APIs or a workaround for this specific Brave Mobile issue.

What you can try, based on the documentation:

#
  1. Disable Prefetch and View Transitions
    Since the error persists even after removing <ClientRouter />, check your astro.config.mjs and ensure that prefetching is fully disabled:

    import { defineConfig } from 'astro/config';
    export default defineConfig({
      prefetch: false
    });
    

    This should prevent the prefetch script from being injected Using with View Transitions.

  2. Verify No Residual Scripts
    After disabling, rebuild your project and inspect the final dist/ output to ensure that no scripts referencing astro:before-preparation, startViewTransition, or navigation.entries remain. The documentation does not mention any other source for these scripts except the view transitions and prefetch features.

  3. Fallback Control
    If you must use <ClientRouter />, you can set its fallback prop to "none" to avoid injecting any animation or polyfill logic in unsupported browsers:

    <ClientRouter fallback="none" />
    

    This will revert to full-page navigation in browsers that do not fully support the View Transitions API Fallback control.

Limitations:
The knowledge sources do not provide a direct solution for handling partial implementations of browser APIs (like Brave Mobile’s window.navigation). There is also no mention of a configuration option to prevent the injection of these scripts based on feature detection or browser type.

#

Summary:

  • Double-check that prefetch and view transitions are fully disabled in your config and code.
  • Use the fallback="none" prop if you must keep <ClientRouter />.
  • If the error persists even after these steps, it may be due to a bug or limitation in Astro’s injected scripts when encountering partially implemented browser APIs, which is not directly addressed in the documentation.

If you have already tried all of the above and the issue remains, the knowledge sources do not contain enough information to provide a definitive fix for this Brave Mobile-specific problem. You may want to report this as a bug to the Astro team, as it appears to be an edge case not currently handled by the framework’s polyfills or feature detection logic.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@brazen cobalt Kapa.ai is still learning and improving, please let me know how I did by reacting below.

brazen cobalt
#

.

#

Thanks for the response.

To clarify and rule out any remaining doubts:

There are absolutely no references to astro:transitions or <ClientRouter /> left in the project anymore (checked with grep across the entire codebase), and the message appears again.

The build output was fully cleaned: .astro/, .vite/, dist/, and even node_modules/.

No component, no third-party library, and no middleware is importing startViewTransition, astro:before-preparation, or touching navigation.entries.

Yet, the production dist/ still contains a <script type="module"> block referencing astro:before-preparation, which executes immediately and throws TypeError: undefined is not an object on Brave Mobile before any of my code runs.

This is not a fallback issue imho it's a runtime-breaking issue, I suspect this could be a bug in Astro's build pipeline but I also suspect I may be wrong lol

Could it be a problem with Brave on iOS which changed something in a silent update and ended up broking things? @sleek beacon

sleek beaconBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Thank you for the detailed clarification.

Based on the knowledge sources, if you have fully removed all references to astro:transitions, <ClientRouter />, and related features from your codebase, and have thoroughly cleaned your build output, there should not be any scripts referencing astro:before-preparation or similar view transitions lifecycle events in your final dist/ output. The documentation states that these scripts are only injected when view transitions or prefetching are enabled, typically via <ClientRouter /> or related configuration Using with View Transitions.

If such a script still appears in your production output after all these features have been removed, the knowledge sources do not provide an explanation or workaround for this scenario. There is no mention of Astro injecting these scripts under any other circumstances, nor is there documentation about a known issue with Brave on iOS causing this specific error.

Given this, the knowledge sources do not contain enough information to definitively determine whether this is a bug in Astro’s build pipeline or a browser-specific issue introduced by a Brave update. Your suspicion that it could be a runtime-breaking issue in Astro, or a change in Brave’s implementation, is reasonable, but cannot be confirmed or denied based on the available documentation.

Summary:

  • The documentation does not describe any scenario where these scripts would be injected without view transitions or prefetching enabled.
  • There is no information about Brave on iOS introducing breaking changes that would cause this error.
  • If the issue persists after all removals and clean builds, and is not present in other browsers, it may be an edge case not covered by current Astro documentation.
#

If you continue to encounter this, it may be best to open an issue with the Astro team, providing your findings and build output for further investigation.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@brazen cobalt Kapa.ai is still learning and improving, please let me know how I did by reacting below.

brazen cobalt
#

Hey, quick update regarding the TypeError: undefined is not an object we reported earlier just in case if someone find it useful, we’ve now confirmed this is not caused by Astro at all.

The same error happens even on, Google.com, our Laravel-powered dashboard, old Astro builds with no transitions or prefetch, even Astro’s own documentation site..

The issue only occurs in Brave Mobile on iOS, and is unrelated to our project code. It seems Brave exposes a partial window.navigation object (probably due to iOS/WebKit constraints), and some internal Brave script throws when accessing .entries.

So we’re treating this as an environmental quirk of Brave, and ignoring the error for now. However, we're still investigating why Brave Mobile triggers a "phantom loading bar" when scrolling or tapping on our site, even without any active navigation or prefetch logic.

Thanks for your help earlier, just wanted to close the loop properly so no one else wastes time debugging something outside of Astro's scope and get mad with that TypeError: undefined is not an object debugging with devtools on macOS.

@sleek beacon

sleek beaconBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Thank you for the update and for sharing your findings. Based on the knowledge sources provided, there is no documentation in Astro that addresses this specific TypeError: undefined is not an object related to window.navigation or .entries on Brave Mobile for iOS. The sources confirm that scripts referencing view transitions or prefetching (such as those using astro:before-preparation) are only injected when those features are enabled in your Astro project, and there is no mention of Astro injecting such scripts in other scenarios or of known compatibility issues with Brave Mobile on iOS Using with View Transitions.

Your conclusion that this is an environmental issue specific to Brave Mobile on iOS, and not caused by Astro, is consistent with the absence of relevant information or workarounds in the Astro documentation. The knowledge sources do not provide any guidance on the "phantom loading bar" behavior in Brave Mobile either.

If you or others encounter similar issues, the documentation suggests verifying that no view transitions or prefetch features are enabled, but beyond that, there is no further troubleshooting advice for this browser-specific quirk.

Thank you for closing the loop and sharing your experience—it will be helpful for others facing similar unexplained errors in Brave Mobile on iOS.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@brazen cobalt Kapa.ai is still learning and improving, please let me know how I did by reacting below.

brazen cobalt
#

Update we’ve finally found the culprit, and it’s hilariously dumb:

After switching branches (from main to an old one like Authors) and back again, the error completely vanished without any changes to the codebase. So in the end, it wasn’t Astro, nor Brave, nor ClientRouter, and not even the view transitions polyfill.

It was likely a corrupted intermediate build artifact (possibly Vite cache or .astro/.vite files) or even the browser (Brave on iOS) holding on to a broken JS file from a previous build.

Doing a normal clean-up (rm -rf dist .astro .vite && npm run build) didn’t solve it, only switching branches triggered a rebuild that fixed whatever was broken. We're leaving this here in case someone else runs into the same phantom TypeError and phantom loading bug, sometimes it's just a cache gremlin playing with your sanity.

Thanks again 🥲