Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-better-sqlite3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@powersync/node": patch
---

Fix loading of `better-sqlite3` in the Node worker so the module is dynamically loaded correctly.

This ensures the Node SDK loads the correct Database constructor when `better-sqlite3` is installed.
4 changes: 3 additions & 1 deletion packages/node/src/db/SqliteWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ export function startPowerSyncWorker(options?: Partial<PowerSyncWorkerOptions>)
},
async loadBetterSqlite3() {
const module = await dynamicImport('better-sqlite3');
return module.default;
return module && typeof module === 'object' && 'default' in module
? module.default
: module;
Comment on lines +87 to +89
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might make it clearer what's going on:

Suggested change
return module && typeof module === 'object' && 'default' in module
? module.default
: module;
// require() gives us the default directly, for an ESM import() we need to use the default export.
return isBundledToCommonJs ? module : module.default;

},
...options
};
Expand Down