ujjwalguptaofficial / JsStore

A complete IndexedDB wrapper with SQL like syntax.
http://jsstore.net/
MIT License
849 stars 109 forks source link

ReferenceError: self is not defined #310

Closed zakaria-chahboun closed 1 year ago

zakaria-chahboun commented 1 year ago

I have this errors:

ReferenceError: self is not defined
jsstore@4.5.0/node_modules/jsstore/dist/jsstore.commonjs2.js:352:36
jsstore@4.5.0/node_modules/jsstore/dist/jsstore.worker.commonjs2.js:1184:17

I believe webpack has set it as self for a certain reason. But in order to work on browser and node you can simply switch to this:

output: {
  // ...
  globalObject: 'this',
},
ujjwalguptaofficial commented 1 year ago

@zakaria-chahboun i can understand why this issue ? but this should not occur in browser environment. Can you tell me where you are using this and more info about your app.

zakaria-chahboun commented 1 year ago

@ujjwalguptaofficial in SvelteKit framework, the code is running in both server-side and client-side! can you do something for that? Thanks! :tulip:

ujjwalguptaofficial commented 1 year ago

@zakaria-chahboun indexedd is client side tech, so in server it won't execute. Do something to make sure it runs inside only client only.

somthing like

if(isClient){
   executeJsStore();
}

Hope this make sense.

zakaria-chahboun commented 1 year ago

i already did that by

import { browser } from '$app/environment';
if(brower){
// .....
}

and it's work fine, But if you can just eliminate the worker.

some libraries support SSR even if it works only in the browser. if you can do that it will be good for SSR frameworks!