local-storage
local-storage copied to clipboard
Reference to "global" in code intended to run in the browser
When I try and use the local storage hook in a vite project, running in dev mode, I get the following error:
Uncaught ReferenceError: global is not defined
Line 14 of local-storage-events.ts references global.window
. As far as I'm aware global
isn't a global variable in browser environments.
From this discussion I've gathered that most, but not all, bundlers transform global
to window
.
Could line 14 be safely rewritten to the following?
if (typeof window.CustomEvent === 'function') {
return;
}
this also fails for me for the exact same reason. any tips on how to fix it? using it in a vite project.
I've put the following
define: {
global: {
window: {}
},
},
in vite.config.ts
to workaround the problem.
I've put the following
define: { global: { window: {} }, },
in
vite.config.ts
to workaround the problem.
Sadly, this doesn't fix it for me - it'd be great to see support of Vite in @rehooks/local-storage
though as it's been around for quite some time & becoming really popular too 😉