Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error with pointer to docs when PGlite is unable to load WASM binary #199

Open
Arrow7000 opened this issue Aug 14, 2024 · 10 comments

Comments

@Arrow7000
Copy link

I'm getting an error when running a transaction in the browser. The function I'm running:

export const replaceSchema = (db: PGlite, schemaStr: SchemaString) => {
  return db.transaction((tx) => {
    tx.exec(`DROP SCHEMA public CASCADE;`);

    return tx.exec(schemaStr);
  });
};

The error:

Uncaught (in promise) RuntimeError: Aborted(CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 64 6f @+0). Build with -sASSERTIONS for more info.
    at abort (@electric-sql_pglite.js?v=74e038dd:461:
@AntonOfTheWoods
Copy link
Contributor

That looks like a WASM problem. Are you using vite and not excluding it from the optimisations?

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

@thorwebdev
Copy link

Yes, adding this to the vite.config.js file did the trick for me. Thank you @AntonOfTheWoods

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  optimizeDeps: {
    exclude: ['@electric-sql/pglite'],
  },
});

@samwillis
Copy link
Collaborator

Although this is due to a bundler and outside of PGlite, we should try and improve the error message here, to indicate what the fix is.

@samwillis samwillis changed the title RuntimeError: Aborted(CompileError: WebAssembly.instantiate(): Improve error with pointer to docs when PGlite is unable to load WASM binary Aug 15, 2024
@Arrow7000
Copy link
Author

Are you using vite and not excluding it from the optimisations?

😅 that is exactly what I was doing. I had no idea I had to exclude it from optimisations. Yeah, a better error message would be amazing, but it does work now! Thanks!

@ixartz
Copy link

ixartz commented Aug 27, 2024

I have a similar issue with Next.js:

RuntimeError: Aborted(). Build with -sASSERTIONS for more info.

I have try to apply a similar change like in Vite optimizeDeps.exclude
In my next.js config, I have the following line:

serverComponentsExternalPackages: ['@electric-sql/pglite'],

PGlite works perfectly with the in-memory FS and it didn't work with Node FS. So, I don't have any issue with the in-memory version, the issue is only with the Node FS.

Any idea?

@lirbank
Copy link

lirbank commented Sep 24, 2024

Possibly related #322 (comment)

@ixartz
Copy link

ixartz commented Sep 24, 2024

@lirbank I also applied serverComponentsExternalPackages (I'm currently at Next.js 14) to make it work. It working with the in-memory FS: https://pglite.dev/docs/filesystems#in-memory-fs
It doesn't work with https://pglite.dev/docs/filesystems#node-fs

In your case, does it work with https://pglite.dev/docs/filesystems#node-fs?

@lirbank
Copy link

lirbank commented Sep 24, 2024

@ixartz got it. I have not tried the node-fs. I am just using PGllite in the browser for now, so I am afraid I can't help. But I am curious to use it for tests on the server at some point.

@ixartz
Copy link

ixartz commented Sep 25, 2024

@lirbank On my side, I didn't have the chance to try in the browser, I'm currently using for local/dev environment with PGLite. I also use for testing.

If you are interested, you can take a look at: https://github.com/ixartz/SaaS-Boilerplate

@electrovir
Copy link

#199 (comment) fixed it for me as well, but I never got any error messages (in Safari), my .exec call simply hung forever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants