ujjwalguptaofficial/JsStore

ReferenceError: self is not defined

zakaria-chahboun opened this issue · 4 comments

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',
},

@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.

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

@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.

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!