Skip to content

fix: support better-sqlite3 v13 - #12971

Closed
Ahmad-Mosha wants to merge 1 commit into
typeorm:masterfrom
Ahmad-Mosha:fix/better-sqlite3-v13
Closed

Ahmad-Mosha wants to merge 1 commit into
typeorm:masterfrom
Ahmad-Mosha:fix/better-sqlite3-v13

Conversation

@Ahmad-Mosha

Copy link
Copy Markdown

Description of change

Closes #12961.

TypeORM's peer range for better-sqlite3 is ^12.0.0, so npm refuses to install v13 alongside TypeORM (ERESOLVE). This PR makes four changes.

  • Peer range. It becomes ^12.0.0 || ^13.0.0.
  • nativeBinding. It is now passed to better-sqlite3 only when it is configured.
    • TypeORM always passed nativeBinding: null.
    • The platform entrypoints added in v13 (e.g. better-sqlite3/linux-x64) throw when the key is present at all, so they couldn't be used through the driver option.
    • v12 and v13's default entrypoint treat a missing key like null, and a configured value is still forwarded unchanged.
  • Tests.
    • New functional tests check that the option is left out when unset and forwarded when set. They use a driver wrapper around the real module, so they run on the current devDependency.
    • The existing nativeBinding test now locates the addon for either version: build/Release/ in v12, prebuilds/ in v13.
  • Docs. drivers/sqlite.md now describes v13's Node.js requirement.

The devDependency stays on v12. v13 is built against Node-API 10, which Node.js 20 lacks, and it segfaults there.

  • Every tests-linux job except cockroachdb runs on Node.js 20.
  • data-source.test.ts always opens a better-sqlite3 connection, so a bump would crash those jobs even for other drivers.
  • typeorm init would scaffold v13 for Node.js 20 users.

This follows the guidance in #11683, and the bump can come with dropping Node.js 20 (#12853). The trade-off is that CI keeps covering v12 only, so v13 was tested locally (below).

Known risk. v13 declares "node": ">=22", which understates its actual requirement (WiseLibs/better-sqlite3#1514). Node.js 22.13.x satisfies that range but lacks Node-API 10. In a simulated install, npm picked v13 there under the new peer range, and v13 crashes the process when the database is opened. This PR doesn't prevent that; the docs only state the requirement. On Node.js 20, npm still picked v12 because v13's engines excludes it. I didn't check pnpm or yarn.

Apart from that requirement, I found no differences in the better-sqlite3 APIs the driver uses. One exception: v13 rejects DataView parameters, which TypeORM itself never creates.

Verification

  • The full better-sqlite3 suite (CI ormconfig, macOS arm64) passed 3108, failed 0 for:

    • v12.11.1 on Node.js 24
    • v13.0.3 on Node.js 24 and 22.23.2
    • v13.0.0 on Node.js 24

    The v13 runs used a local devDependency bump that is not part of this PR.

  • The new "not set" test fails when the driver change is reverted.

  • A DataSource using driver: require("better-sqlite3/darwin-arm64") fails on master and works with this PR.

  • v13 new Database() segfaults on Node.js 20.20.2 and 22.13.1, and works on 22.14.0, 22.23.2, 24 and 26.11.1. I checked this on macOS and on Linux arm64 in Docker.

  • pnpm install --frozen-lockfile passes with the lockfile unchanged, and typecheck, ESLint and Prettier pass.

Not tested locally:

  • Windows, Linux x64, and v12 on Node.js 20. CI covers these with v12.
  • Electron, Bun, musl, source builds and SQLCipher.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links a relevant issue using a closing keyword: Closes #12961
  • There are new or updated tests validating the change (tests/**.test.ts)
  • Documentation has been updated to reflect this change (docs/docs/**.md)

Widen the better-sqlite3 peer dependency range to ^12.0.0 || ^13.0.0.

Only pass `nativeBinding` to better-sqlite3 when it is configured. The
platform entrypoints added in v13 (e.g. `better-sqlite3/linux-x64`) throw
when the option is present, even as `null`, so using one through the
`driver` option failed.

The devDependency stays on v12: v13 requires Node-API 10, which Node.js 20
lacks, and CI still tests Node.js 20.

Closes typeorm#12961
@github-actions github-actions Bot added the linked-issue PR references an issue label Oct 15, 2026

@maginseb maginseb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good to me

@mogretici

Copy link
Copy Markdown

An independent data point for the verification section: in our project's suite, the SQLite storage and TypeORM sqlite-driver tests (683) passed 683/683 on Node 26.13 with [email protected] in place of 12.11.1. We stayed on 12 for now because of the peer range this PR widens, plus the Node 22.12/22.13 segfault from WiseLibs/better-sqlite3#1514 that the PR already mentions. Would be great to see this reviewed.

@alumni

alumni commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Already bumped up most packages in #13070. You should be able to use better-sqlite3@^13 in the next minor/patch version that we will release.

@alumni alumni closed this Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linked-issue PR references an issue

Development

Successfully merging this pull request may close these issues.

support better-sqlite3 v13

4 participants