typeorm/typeorm · critical · DriverPackageNotInstalledError

SQLite package has not been found installed. Please run "npm

Error message

SQLite package has not been found installed. Please run "npm install better-sqlite3".

What it means

Thrown as DriverPackageNotInstalledError by BetterSqlite3Driver.loadDependencies when `require('better-sqlite3')` throws (or no explicit driver was supplied via options.driver). The driver needs the native better-sqlite3 module to open a database connection; without it, initialization fails fast with an actionable install hint.

Source

Thrown at src/driver/better-sqlite3/BetterSqlite3Driver.ts:183

        // turn on WAL mode to enhance performance
        if (this.options.enableWAL) {
            databaseConnection.pragma("journal_mode = WAL")
        }

        return databaseConnection
    }

    /**
     * If driver dependency is not given explicitly, then try to load it via "require".
     */
    protected loadDependencies(): void {
        try {
            const sqlite =
                this.options.driver ?? PlatformTools.load("better-sqlite3")
            this.sqlite = sqlite
        } catch (e) {
            throw new DriverPackageNotInstalledError("SQLite", "better-sqlite3")
        }
    }

    /**
     * Auto creates database directory if it does not exist.
     *
     * @param dbPath
     */
    protected async createDatabaseDirectory(dbPath: string): Promise<void> {
        await fs.mkdir(dbPath, { recursive: true })
    }

    /**
     * Performs the attaching of the database files. The attachedDatabase should have been populated during calls to #buildTableName
     * during EntityMetadata production (see EntityMetadata#buildTablePath)
     *
     * https://sqlite.org/lang_attach.html
     */

View on GitHub (pinned to 04ff4daedc)

Solutions

  1. Run `npm install better-sqlite3` (and ensure it is in dependencies, not devDependencies).
  2. If using Electron, run electron-rebuild / @electron/rebuild so the native binary matches the runtime ABI.
  3. Pass the driver instance explicitly via DataSource options ({ type:'better-sqlite3', driver: require('better-sqlite3') }) when bundling hides the module from PlatformTools.load.

Example fix

// before
// DataSource created with type:'better-sqlite3' but package missing

// after (shell)
// npm install better-sqlite3
// (and for electron) npx electron-rebuild -f -w better-sqlite3
Defensive patterns

Strategy: validation

Validate before calling

// Verify the package resolves before initializing the DataSource
function canRequire(name: string): boolean { try { require.resolve(name); return true } catch { return false } }
if (!canRequire('better-sqlite3')) throw new Error('Run: npm install better-sqlite3')

Type guard

const hasBetterSqlite3 = (): boolean => { try { require.resolve('better-sqlite3'); return true } catch { return false } }

Prevention

When it happens

Trigger: Initializing a DataSource with type 'better-sqlite3' before running npm install better-sqlite3; deploying without production deps (NODE_ENV mismatch); a fresh checkout where node_modules is incomplete; a native build that failed to compile for the current Node ABI.

Common situations: Missing peer/optional dependency in CI; Electron/native-rebuild issues leaving better-sqlite3 unbuilt; monorepo hoisting that drops the package; CI cache missing native artifacts.

Related errors


AI-assisted analysis of typeorm/typeorm@04ff4daedc (2026-08-03). Data as JSON: /data/errors/4eb565efb736619b.json. Report an issue: GitHub.