- /
-
- Archived Posts /
- Fixing "Global is not Definied" in Vite and Vue 3
Fixing "Global is not Definied" in Vite and Vue 3
Archived Posts from previous blogs that might still be useful to someone.
Last modified 2023-01-25
While starting my first full project with Vite + Vue 3 after trying to start using Pinia, I as getting an error:
ReferenceError: global is not defined at node_modules/immediate/lib/mutation.js (mutation.js:6:16) at __require (chunk-DFKQJ226.js?v=321f6407:8:50) at node_modules/immediate/lib/index.js (index.js:5:3) at __require (chunk-DFKQJ226.js?v=321f6407:8:50) at index-browser.es.js:1:23
After commenting lines in and out, I was able to trace down that the root of the issue was coming from my PouchDB import line, which led me to this Github Issue solution.
In my case it seems like the only change that was necessary is to add this to the top of main.js
:
import process from "process/browser";
window.process = process;
window.global = window;
// Rest of your file goes here 👇🏻
Hope this helps you not struggle for an hour 💕