Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

npx knex migrate:make stops with Cannot find module for the SQLite driver

Your error

Knex: run3 more lines it can show

Fix it fast

Most common cause, 1 of 2

The driver package for the knexfile's client is not installed

Install the driver that matches client in the knexfile, as a normal dependency of the same project.

Fix
npm install sqlite3

// knexfile.js
module.exports = {
  development: {
    client: 'sqlite3',          // or 'better-sqlite3' with that package
    connection: { filename: './dev.sqlite3' },
  },
};
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Knex prints Knex: run $ npm install sqlite3 --save and then Cannot find module when the driver package for the knexfile client is missing from the project. Knex 1.0.x loaded @vscode/sqlite3 yet still told you to install sqlite3, so following the hint changed nothing; upgrade to Knex 3, which loads sqlite3 again. Applies to Knex 2.0 to 3.3.

  • Applies to Knex 3.3.0, sqlite3 6.0, better-sqlite3 13.2, Node.js 22, 24 and 26
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Ask npm which Knex and which SQLite driver this project really has, and read the client name in the knexfile. Knex 2 or newer with no driver under it is cause 1. Knex 1.0.x, or an error that names @vscode/sqlite3, is cause 2.

Run this first
npm ls knex sqlite3 better-sqlite3 @vscode/sqlite3
grep -n "client" knexfile.js

Then find the line you see in this list and open its fix:

  1. 1The driver package for the knexfile's client is not installednpm ls shows knex 2.x or 3.x but no sqlite3 (or better-sqlite3) entry, and the error says Cannot find module 'sqlite3'
  2. 2Knex 1.0.x asks for @vscode/sqlite3 while its hint still says sqlite3The last line names '@vscode/sqlite3', or npm ls shows knex@1.0.x, and installing sqlite3 as told did not help

What does the error look like?

  • Knex: run
  • $ npm install sqlite3 --save
  • Cannot find module 'sqlite3'
  • Cannot find module '@vscode/sqlite3'

Cause 1 of 2

The driver package for the knexfile's client is not installed

You seenpm ls shows knex 2.x or 3.x but no sqlite3 (or better-sqlite3) entry, and the error says Cannot find module 'sqlite3'

Check

Knex does not ship any database driver. Its package lists sqlite3, better-sqlite3, pg, mysql2 and the others as optional peer dependencies, so installing knex alone brings none of them. The sqlite3 dialect loads its driver with require('sqlite3'), and when that throws, Knex prefixes the original Cannot find module error with its Knex: run install hint.

Check
node -e "require('sqlite3')"

Fix

Install the driver that matches client in the knexfile, as a normal dependency of the same project. Choose one SQLite driver: client 'sqlite3' needs the sqlite3 package, client 'better-sqlite3' needs better-sqlite3.

Fix
npm install sqlite3

// knexfile.js
module.exports = {
  development: {
    client: 'sqlite3',          // or 'better-sqlite3' with that package
    connection: { filename: './dev.sqlite3' },
  },
};

Verify

The driver loads on its own, and the migration command writes a new file into the migrations folder.

Verify
node -e "require('sqlite3'); console.log('driver loads')"
npx knex migrate:make test

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 2

Knex 1.0.x asks for @vscode/sqlite3 while its hint still says sqlite3

You seeThe last line names '@vscode/sqlite3', or npm ls shows knex@1.0.x, and installing sqlite3 as told did not help

Check

Knex 1.0.0 replaced the sqlite3 driver with @vscode/sqlite3. In 1.0.x the dialect requires '@vscode/sqlite3', but the hint is built from the driver name, which stayed 'sqlite3'. The message therefore asks for npm install sqlite3, you run it, and the require of @vscode/sqlite3 fails exactly as before. Knex 2.0.0 restored the sqlite3 package, and current 3.x requires sqlite3 again.

Check
npx knex --version

Fix

Upgrade Knex to the current major and keep the sqlite3 package the hint asked for. Read the Knex changelog between your version and 3.x before upgrading a production app, since two major versions are skipped.

Fix
npm install knex@3 sqlite3
npm uninstall @vscode/sqlite3

Verify

The version command shows the same 3.x number on the Knex CLI and Knex Local lines, and migrate:make runs without the driver error.

Verify
npx knex --version
npx knex migrate:make test

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Add the SQLite driver to dependencies in the same commit that sets client in the knexfile, so a fresh clone has both.
  • Run migrations through an npm script or npx inside the project, and check that npx knex --version reports the same number for Knex CLI and Knex Local.
  • Keep knex on a caret range of the current major and commit the lockfile, so a stray 1.0.x install cannot come back.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Workforce, DCOR.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.