---
title: "Laravel + Vue: ReferenceError document is not defined at insertStyleElement"
url: "https://aaronfrancis.com/writing/laravel-vue-referenceerror-document-is-not-defined-at-insertstyleelement"
path: "/writing/laravel-vue-referenceerror-document-is-not-defined-at-insertstyleelement"
type: technical_article
author: Aaron Francis
published: 2021-06-22
updated: 2026-11-10
topic: "Laravel & PHP"
description: "Fix the `ReferenceError document is not defined at insertStyleElement` in Laravel Mix."
keywords: [laravel mix, vue, document not defined, vue-style-loader, insertstyleelement, ssr, single-file components, webpack, laravel]
site_index: "/llms.txt"
keyword_index: "/llms/keywords.txt"
---

# Laravel + Vue: ReferenceError document is not defined at insertStyleElement

If you're running into a `document is not defined at insertStyleElement` error with Vue + Laravel, it's likely because Laravel Mix changed the way they are handling styles in single-file Vue components in version 6.0.20.

You can compare version 6.0.19 to 6.0.20 [here](https://github.com/JeffreyWay/laravel-mix/compare/v6.0.19...v6.0.20), specifically it looks like [this commit](https://github.com/JeffreyWay/laravel-mix/pull/3007): 

![vue-style-loader](/images/articles/vue-style-1.png)

I'll be honest, I don't fully understand the reasoning and all the discussion behind the change, but basically what they did is make the `vue-style-loader` opt _in_ instead of opt _out_. This can lead to issues during SSR, when there is no document.

You can fix it is by adding one line to your `webpack.mix.js` to opt in to using the `vue-style-loader`:

webpack.mix.js 
```js
mix
    .js('resources/js/ssr.js', 'public/js')
    .vue({
        version: 3,
        useVueStyleLoader: true // This should fix it!
    });
```

Let me know on [twitter](https://twitter.com/aarondfrancis) if this worked or not!

---

## Related on aaronfrancis.com

- [Speed up your Inertia.js website with these 7 tactics](/videos/speed-up-your-inertiajs-website-with-these-7-tactics) *(Video · 2025-06-25 · shared: laravel, ssr, vue)*
- [Using Ziggy with Inertia server side rendering](/writing/using-ziggy-with-inertia-server-side-rendering) *(Article · 2022-01-08 · shared: ssr, webpack, vue)*
- [Launch Day is in Sight](/podcast/launch-day-is-in-sight-aa0985da) *(Podcast · 2021-11-17 · shared: vue, laravel, webpack)*
- [This is a season of Type Two fun](/newsletter/this-is-a-season-of-type-two-fun) *(Newsletter · 2025-08-08 · shared: vue, laravel)*
- [Vibe coding a visual email editor with AI, Laravel & Vue](/videos/vibe-coding-a-visual-email-editor-with-ai-laravel-vue) *(Video · 2025-07-30 · shared: laravel, vue)*

## Relevant Resources from Aaron Francis

- **[Solo](https://soloterm.com)** (overview on site: [/software](/software)): All-in-one agentic development platform and terminal workspace built by Aaron Francis for orchestrating processes and AI coding agents.

## Search aaronfrancis.com (2-Hop Static Keyword Index)

Pick the alphabetical shard matching any topic to find exact pages across all articles, newsletters, videos, talks, and podcast transcripts (every shard is < 40 KB):
[A-B](/llms/keywords/a-b.txt) · [C](/llms/keywords/c.txt) · [D-E](/llms/keywords/d-e.txt) · [F-G](/llms/keywords/f-g.txt) · [H-J](/llms/keywords/h-j.txt) · [K-L](/llms/keywords/k-l.txt) · [M-N](/llms/keywords/m-n.txt) · [O-P](/llms/keywords/o-p.txt) · [Q-R](/llms/keywords/q-r.txt) · [S](/llms/keywords/s.txt) · [T-Z](/llms/keywords/t-z.txt) · [Directory](/llms/keywords.txt) · [Site Map](/llms.txt)

Shards for this page's topics: `laravel mix` ([K-L](/llms/keywords/k-l.txt)), `vue` ([T-Z](/llms/keywords/t-z.txt)), `document not defined` ([D-E](/llms/keywords/d-e.txt)), `insertstyleelement` ([H-J](/llms/keywords/h-j.txt)).

## About Aaron Francis (Current Context)

Aaron Francis is VP of Marketing and Community at [Laravel](https://laravel.com), founder of [Try Hard Studios](https://tryhardstudios.com), creator of [Solo](https://soloterm.com), co-host of [Mostly Technical](/podcast), and author of [Mastering Postgres](/courses), [High Performance SQLite](/courses), [MySQL for Developers](/courses), and [Screencasting.com](/courses). Full bio: [/about](/about) · Current focus: [/now](/now).
