Registry / database / sqlite-esm

sqlite-esm

JSON →
library3.42.0-build6jsnpmunverified

SQLite Wasm conveniently wrapped as an ES Module. Current stable version is 3.42.0-build6. This package provides a zero-dependency, drop-in ES Module wrapper for SQLite's official WebAssembly build, allowing SQLite to run in the browser. Key differentiators: supports both main thread (transient storage) and worker thread (with origin private file system for persistent storage), maintains unmodified upstream code, ships TypeScript types, and requires specific HTTP headers (COOP/COEP) for OPFS support. Released as needed per SQLite version bumps.

npm install sqlite-esm
INSTALL
IMPORT
SIG · SQLITE-ESM
S
sqlite-esm
databasejavascriptv3.42.0-build6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sqlite3InitModule
import sqlite3InitModule from '@sqlite.org/sqlite-wasm';
Default export: a function that returns a promise resolving to the sqlite3 API object.

Shows default import, initializing the module, creating an in-memory database, executing SQL, and fetching results.

import sqlite3InitModule from '@sqlite.org/sqlite-wasm'; const log = (...args) => console.log(...args); sqlite3InitModule({ print: log, printErr: (...args) => console.error(...args), }).then((sqlite3) => { const db = new sqlite3.oo1.DB(':memory:', 'c'); db.exec('CREATE TABLE t(a); INSERT INTO t VALUES(1);'); const rows = db.exec('SELECT * FROM t', { rowMode: 'object' }); log(rows); db.close(); });
Debug
Known issues
gotchaOPFS database requires Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp headers.
fix
Set the HTTP headers on the server or in dev server config (e.g., Vite's server.headers).
affects: >=3.0.0
gotchaVite requires optimizeDeps.exclude: ['@sqlite.org/sqlite-wasm'] to work correctly.
fix
Add the exclusion in vite.config.js as shown in the README.
affects: >=3.0.0
gotchaThe package wraps official SQLite Wasm unmodified; do not file issues here for SQLite bugs.
fix
Report SQLite bugs upstream at https://www.sqlite.org/src/wiki?name=Bug+Reports
affects: all
gotchaMain thread usage does not support OPFS; use only transient or 'ct' flag databases.
fix
For persistent storage, use the worker thread variant with OpfsDb.
affects: all
Errors
Common errors & fixes
Failed to initialize SQLite3 module: TypeError: Cannot read properties of undefined (reading 'then')
Forgetting to await or use .then() on the init module call.
fix
Use sqlite3InitModule({...}).then(sqlite3 => { ... }) or await sqlite3InitModule({...}).
Cross-Origin-Embedder-Policy: require-corp is not set
Missing or incorrect HTTP headers when using OPFS.
fix
Set 'Cross-Origin-Embedder-Policy: require-corp' and 'Cross-Origin-Opener-Policy: same-origin' headers.
TypeError: sqlite3.oo1.OpfsDb is not a constructor
Trying to use OpfsDb in the main thread or without proper COOP/COEP headers.
fix
Use OpfsDb only in a worker thread with correct HTTP headers.
Upgrade
Version history
3.42.0-build6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
18
Meta
2
Amazon
1
OpenAI (training)
1
Resources
sqlite-esm — npm install sqlite-esm · libregistry