pglite icon indicating copy to clipboard operation
pglite copied to clipboard

Invalid FS bundle size

Open dugoalberto opened this issue 1 year ago • 14 comments

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

dugoalberto avatar Oct 28 '24 09:10 dugoalberto

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

binarytide avatar Nov 01 '24 13:11 binarytide

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

binarytide avatar Nov 02 '24 00:11 binarytide

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 avatar Nov 02 '24 00:11 binarytide

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

binarytide avatar Nov 02 '24 02:11 binarytide

Hi, using pglite via import { PGlite } from "https://cdn.jsdelivr.net/npm/@electric-sql/pglite/dist/index.js" It has been working perfectly fine for about a week or two, until it stopped working with following error: Uncaught (in promise) Error: Invalid FS bundle size: 2987805 !== 4827589 getPreloadedPackage postgres.js:9 loadPackage postgres.js:9 Module postgres.js:9 Module postgres.js:9 Ee postgres.js:9 te postgres.js:9 table_edit.js:9 Any help appreciated.

ludoaubert avatar Dec 01 '24 11:12 ludoaubert

I cleared the web browser cache (FF in my case) and the error is gone.

ludoaubert avatar Dec 01 '24 17:12 ludoaubert

i met the problem too , it appears when i try to create a db, i have worked 2 days for it , but failed

mainytht avatar Feb 04 '25 09:02 mainytht

just clear the web browser's cache

ludoaubert avatar Feb 04 '25 09:02 ludoaubert

I have the exact same error. Using Vite & Vue with chrome.

lroal avatar May 17 '25 12:05 lroal

Hey, did anyone get the solution?

Noothan-am avatar May 19 '25 18:05 Noothan-am

Hey, did anyone get the solution?

For me, as running Vue, I found the solution here: https://pglite.dev/docs/bundler-support . There is also a workaround for Nextjs there. vite config

import { defineConfig } from 'vite'

export default defineConfig({
  optimizeDeps: {
    exclude: ['@electric-sql/pglite'],
  },
})

next config

const nextConfig = {
  swcMinify: false,
  transpilePackages: [
    '@electric-sql/pglite-react', // Optional
    '@electric-sql/pglite',
  ],
}

export default nextConfig

lroal avatar May 20 '25 07:05 lroal

@lroal what is the solution for reactjs

Noothan-am avatar May 20 '25 12:05 Noothan-am

@lroal what is the solution for reactjs

Actually not sure. I thought it was setting the nextjs config as described above. Did you try that ? And also deleting any cache.

lroal avatar May 20 '25 12:05 lroal

I had to add the worker if anyone else is facing that issue. The docs don't show that.

  optimizeDeps: {
    exclude: [
      "@electric-sql/pglite",
      "@electric-sql/pglite/worker",
    ],
  },

DO NOT ADD TO ROLL UP

  build: {
    ...,
    rollupOptions: {
      external: ["@electric-sql/pglite"],
    },
  },

jay-babu avatar Aug 31 '25 19:08 jay-babu