Skip to content

vue-doctor/nuxt/nuxt-no-window-in-ssr ​

Guard browser globals with if (import.meta.client) or access them inside onMounted()

PropertyValue
CategoryNuxt
Default Severitywarning
Confidencemedium
FixableNo
Engineoxlint
Sincev1.0.0
Frameworksnuxt
Test filesNot checked (which files)

Why it matters ​

Guard browser globals with if (import.meta.client) or access them inside onMounted()

How to fix ​

Review the finding and update the code according to best practices below.

Agent Guidance ​

Browser globals do not exist during SSR. Guard access with if (import.meta.client) or move it into onMounted(). Code that only runs from client-only places is already fine: lifecycle hooks other than setup, template event handlers, DOM event listeners, watch callbacks without immediate, post-flush effects, *.client.* files and pages with ssr: false in routeRules. A function that is exported or returned from a composable cannot be traced to its callers; guard it inside.


Rule source: vue-doctor/nuxt/nuxt-no-window-in-ssr

Released under the MIT License.