electric-sql / pglite

Lightweight WASM Postgres with real-time, reactive bindings.
https://pglite.dev
Apache License 2.0
9.45k stars 204 forks source link

Invalid FS bundle size #409

Open dugoalberto opened 3 weeks ago

dugoalberto commented 3 weeks ago

HI everyone, I'm trying to use electric-sql without the need of using cdn and I got this error while I'm loading the db:

Uncaught (in promise) Error: Invalid FS bundle size: 792 !== 2987805
    at Object.getPreloadedPackage (electric-sql-bundle.js:11787:39)
    at loadPackage (electric-sql-bundle.js:2021:84)
    at electric-sql-bundle.js:2133:7
    at electric-sql-bundle.js:2134:7
    at te3.Pe2 (electric-sql-bundle.js:11821:57)

I'm using a bundled version (electric-sql-bundle.js) created with esbuild

this is the code of the esbuild const esbuild = require('esbuild');

esbuild.build({
target: 'esnext',
  bundle: true,
  splitting : false,
  format: 'esm',
  entryPoints: [
    './node_modules/@electric-sql/pglite/dist/index.js',
  ],
  outfile: './dist/electric-sql-bundle.js',
  define: {
    'process.env.NODE_ENV': JSON.stringify('development'),
  },
  external: ['@electric-sql/pglite'],
}).catch(() => process.exit(1));

Probably i did something wrong but i dont find any kind of documentation related to this.

If I did something wrong in the bug report im sorry

binarytide commented 2 weeks ago

I'm getting this as well from following the getting started instructions(yarn)

binarytide commented 2 weeks ago

solution(for me at least): https://discord.com/channels/933657521581858818/934234468514922567/1301530280212828221

binarytide commented 2 weeks ago

I use quasar so I had to apply this in my quasar.conf.js:

 extendViteConf(viteConf) {
        // Extend the Vite configuration to exclude dependencies from optimization
        viteConf.optimizeDeps = {
          ...viteConf.optimizeDeps,
          exclude: ['@electric-sql/pglite'], // replace 'some-library' with the module you want to exclude
        }

        // Optional: Exclude from Rollup build as well
        viteConf.build = {
          ...viteConf.build,
          rollupOptions: {
            ...viteConf.build?.rollupOptions,
            external: ['@electric-sql/pglite'], // ensure that Rollup does not bundle this module
          },
        }
      },
binarytide commented 2 weeks ago

related docs: https://pglite.dev/docs/bundler-support