{"id":"4eb565efb736619b","repo":"typeorm/typeorm","slug":"sqlite-package-has-not-been-found-installed-pleas","errorCode":null,"errorMessage":"SQLite package has not been found installed. Please run \"npm install better-sqlite3\".","messagePattern":"SQLite package has not been found installed\\. Please run \"npm install better-sqlite3\"\\.","errorType":"exception","errorClass":"DriverPackageNotInstalledError","httpStatus":null,"severity":"critical","filePath":"src/driver/better-sqlite3/BetterSqlite3Driver.ts","lineNumber":183,"sourceCode":"\n        // turn on WAL mode to enhance performance\n        if (this.options.enableWAL) {\n            databaseConnection.pragma(\"journal_mode = WAL\")\n        }\n\n        return databaseConnection\n    }\n\n    /**\n     * If driver dependency is not given explicitly, then try to load it via \"require\".\n     */\n    protected loadDependencies(): void {\n        try {\n            const sqlite =\n                this.options.driver ?? PlatformTools.load(\"better-sqlite3\")\n            this.sqlite = sqlite\n        } catch (e) {\n            throw new DriverPackageNotInstalledError(\"SQLite\", \"better-sqlite3\")\n        }\n    }\n\n    /**\n     * Auto creates database directory if it does not exist.\n     *\n     * @param dbPath\n     */\n    protected async createDatabaseDirectory(dbPath: string): Promise<void> {\n        await fs.mkdir(dbPath, { recursive: true })\n    }\n\n    /**\n     * Performs the attaching of the database files. The attachedDatabase should have been populated during calls to #buildTableName\n     * during EntityMetadata production (see EntityMetadata#buildTablePath)\n     *\n     * https://sqlite.org/lang_attach.html\n     */","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/driver/better-sqlite3/BetterSqlite3Driver.ts#L165-L201","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run `npm install better-sqlite3` (and ensure it is in dependencies, not devDependencies).","If using Electron, run electron-rebuild / @electron/rebuild so the native binary matches the runtime ABI.","Pass the driver instance explicitly via DataSource options ({ type:'better-sqlite3', driver: require('better-sqlite3') }) when bundling hides the module from PlatformTools.load."],"exampleFix":"// before\n// DataSource created with type:'better-sqlite3' but package missing\n\n// after (shell)\n// npm install better-sqlite3\n// (and for electron) npx electron-rebuild -f -w better-sqlite3","handlingStrategy":"validation","validationCode":"// Verify the package resolves before initializing the DataSource\nfunction canRequire(name: string): boolean { try { require.resolve(name); return true } catch { return false } }\nif (!canRequire('better-sqlite3')) throw new Error('Run: npm install better-sqlite3')","typeGuard":"const hasBetterSqlite3 = (): boolean => { try { require.resolve('better-sqlite3'); return true } catch { return false } }","tryCatchPattern":null,"preventionTips":["Keep better-sqlite3 in dependencies (not devDependencies).","Rebuild native bindings after Node/Electron upgrades.","Validate presence at bootstrap in test/prod environments."],"tags":["better-sqlite3","dependency","native-module","setup","typeorm"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}