amark / gun

An open source cybersecurity protocol for syncing decentralized graph data.
https://gun.eco/docs
Other
18.03k stars 1.16k forks source link

dare is not a function #1265

Closed bitdom8 closed 1 year ago

bitdom8 commented 2 years ago

tried importing this import 'gun/lib/store' on sveltekit with vite 3.0.2 got an error " dare is not a function"

weirdo-neutrino commented 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

maxbaluev commented 1 year ago

I have same error but with vite, @amark @weirdo-neutrino maybe you know possible ways to fix it?

bitdom8 commented 1 year ago

I stoped and pass to surrealdb @maxbaluev . My Q's stayed unanswered

amark commented 1 year ago

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.

davidascii commented 1 year ago

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'

...
bitdom8 commented 1 year ago

stopped using gunjs. Using surrealdb now. documentation, webpage itself are very not user friendly