Closed bitdom8 closed 1 year ago
I had the same error. Using vite, sveltekit. Sveltekit has prerendering (at build time), SSR (at request time). You need to disable SSR for a page that use Gun. It can be done in +page.js
. More at https://kit.svelte.dev/docs/page-options#ssr
I have same error but with vite, @amark @weirdo-neutrino maybe you know possible ways to fix it?
I stoped and pass to surrealdb @maxbaluev . My Q's stayed unanswered
Did you try Weirdo-Neutrino's advice? This seems specifically related to svelte doing "magic", since its not reporting happening with regular JS (correct me if wrong). Maybe file a bug with svelte? Or disable what weirdo said, looks like they answered you.
Just follow their tutorial for GUN with VITE. You need to exclude some packages from the build (like the 'text-encoding'). It's working fine for me with the following:
vite.config
const moduleExclude = match => {
const m = id => id.indexOf(match) > -1
return {
name: `exclude-${match}`,
resolveId(id) {
if (m(id)) return id
},
load(id) {
if (m(id)) return `export default {}`
},
}
}
export default defineConfig({
...,
plugins: [..., moduleExclude('text-encoding')],
resolve: ...,
build: ...,
optimizeDeps: {
include: [
'gun',
'gun/gun',
'gun/sea',
'gun/sea.js',
'gun/lib/then',
'gun/lib/webrtc',
'gun/lib/radix',
'gun/lib/radisk',
'gun/lib/store',
'gun/lib/rindexed',
]
}
});
My app
import Gun from "gun";
import 'gun/sea.js'
import 'gun/lib/radix'
import 'gun/lib/radisk'
import 'gun/lib/store'
import 'gun/lib/rindexed'
import 'gun/lib/webrtc'
import 'gun/nts'
...
stopped using gunjs. Using surrealdb now. documentation, webpage itself are very not user friendly
tried importing this import 'gun/lib/store' on sveltekit with vite 3.0.2 got an error " dare is not a function"