electric-sql / electric-sql/pglite
PGlite constructor vs. PGlite.create issue
- Dominant language
- TypeScript
- Stars
- 16k
- Forks
- 442
- Avg merge
- 20h 19m
- Merged PRs (30d)
- 7
Description
Copied from our public Discord channel: https://discord.com/channels/933657521581858818/1212676471588520006/1397116203998117910
I've encountered this error many times while developing my project. You can avoid it by instantiating the client using asynchronous static factory method `PGlite.create()`.
Please check the below sample code:
```javascript
const pgOption = {
fs: new IdbFs("pglite-webworker-dump-test"),
relaxedDurability: true,
extensions: { live },
};
const queryString = `SELECT * FROM dummy_data LIMIT 10;`;
async function createPGInstanceError() {
const pg1 = new PGlite(pgOption);
const pg2 = new PGlite(pgOption);
// Throws `Error: Failed to execute 'compile' on 'WebAssembly': Cannot compile WebAssembly.Module from an already read Response`
const queryResult1 = await pg1.exec(queryString);
const queryResult2 = await pg2.exec(queryString);
}
async function createPGInstanceSuccess() {
const pg1 = await PGlite.create(pgOption);
const pg2 = await PGlite.create(pgOption);
// It works!
const queryResult1 = await pg1.exec(queryString);
const queryResult2 = await pg2.exec(queryString);
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.