AmusedGrape
AmusedGrape12mo ago

LocalStorage Override

I'm using a library (@supabase/supabase-js), and I'm compiling my Deno app into an executable, however when I run it I get: error: Uncaught NotSupported: LocalStorage is not supported in this context. The weird thing, is that I have a custom storage adapter for Supabase (using SQLite more or less) however I'm still getting this issue. My question is, is it possible to override the localStorage usage in a third-party library so I can use this executable? Thanks!
8 Replies
ioB
ioB12mo ago
I haven't tested it, but a hacky way to do this is potentially overriding the prototype. Something like:
// no-op
Storage.prototype.setItem = () => {}
// no-op
Storage.prototype.setItem = () => {}
but for all of the methods
AmusedGrape
AmusedGrape12mo ago
yeah tried that, same issue occurs gotrue-js (the lib where the error occurs) apparently uses globalThis.localStorage
ioB
ioB12mo ago
a potentially better way of doing this is using an import map to point gotrue-js to a patched version
AmusedGrape
AmusedGrape12mo ago
oh smart could deno like be seeing the localStorage when parsing my code or something? really trying to figure out what's going on here lol
ioB
ioB12mo ago
not sure what the details are, @crowlkats any ideas?
crowlKats
crowlKats12mo ago
localstorage is persistent, and as such requires a place to write a file, and since that is not settable, that is the reason you cannot use it when compiled
ioB
ioB12mo ago
sure, but in this case we are using a library that uses it and we want to prevent it from doing that
AmusedGrape
AmusedGrape12mo ago
still looking for a solution here, any ideas?