# Nuxt: ReferenceError: window is not defined / 500 Internal Server Error during SSR

**Code:** `Nuxt: window/document/localStorage is not defined (SSR)` · **Category:** Vue · **Seen on:** Vue, Node.js

Code touching browser globals ran on the server during Nuxt SSR.

## Meaning

Run browser-only code in `onMounted`, guard with `import.meta.client`/`process.client`, wrap components in `<ClientOnly>`, or import libraries lazily (`defineAsyncComponent`, `await import()` inside `onMounted`). Plugins can be client-only (`plugin.client.ts`).

## Common causes

- `window`/`document` in setup or module top-level
- Library accessing browser APIs on import
- Plugin running on server
- `localStorage` in store initialisation
- Charts/editors/maps

## Quick fix

1. `if (import.meta.client) { ... }` or `onMounted`
2. `<ClientOnly>` around browser-only components
3. Name plugin `foo.client.ts`

## Detailed fix by platform

### Nuxt

1. `onMounted(() => { const w = window.innerWidth; });`

## How to diagnose

1. **Where** — setup/top-level?
2. **Guard** — import.meta.client?
3. **Library** — Browser-only?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/vue/nuxt-window-is-not-defined-ssr)
