Knex imports sqlite in migrate:make when told to use pg
See original GitHub issueEnvironment
Knex version: 1.0.5 Database + version: Postgres 14 OS: macOS 12.3
Bug
knex migrate:make foo
wants (and fails) to load @vscode/sqlite3
even though the client is set to pg
:
❯ yarn knex migrate:make foo
yarn run v1.22.17
$ /Users/semenov/tmp/p1/node_modules/.bin/knex migrate:make foo
Knex: run
$ npm install @vscode/sqlite3 --save
Cannot find module '@vscode/sqlite3'
Require stack:
- /Users/semenov/tmp/p1/node_modules/knex/lib/dialects/sqlite3/index.js
- /Users/semenov/tmp/p1/node_modules/knex/lib/knex-builder/internal/config-resolver.js
- /Users/semenov/tmp/p1/node_modules/knex/lib/knex-builder/Knex.js
- /Users/semenov/tmp/p1/node_modules/knex/lib/index.js
- /Users/semenov/tmp/p1/node_modules/knex/knex.js
- /Users/semenov/tmp/p1/node_modules/knex/bin/cli.js
Error: Cannot find module '@vscode/sqlite3'
Require stack:
- /Users/semenov/tmp/p1/node_modules/knex/lib/dialects/sqlite3/index.js
- /Users/semenov/tmp/p1/node_modules/knex/lib/knex-builder/internal/config-resolver.js
- /Users/semenov/tmp/p1/node_modules/knex/lib/knex-builder/Knex.js
- /Users/semenov/tmp/p1/node_modules/knex/lib/index.js
- /Users/semenov/tmp/p1/node_modules/knex/knex.js
- /Users/semenov/tmp/p1/node_modules/knex/bin/cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Client_SQLite3._driver (/Users/semenov/tmp/p1/node_modules/knex/lib/dialects/sqlite3/index.js:33:12)
at Client_SQLite3.initializeDriver (/Users/semenov/tmp/p1/node_modules/knex/lib/client.js:190:26)
at new Client (/Users/semenov/tmp/p1/node_modules/knex/lib/client.js:75:12)
at new Client_SQLite3 (/Users/semenov/tmp/p1/node_modules/knex/lib/dialects/sqlite3/index.js:22:5)
at knex (/Users/semenov/tmp/p1/node_modules/knex/lib/knex-builder/Knex.js:12:28)
at initKnex (/Users/semenov/tmp/p1/node_modules/knex/bin/cli.js:74:10)
/Users/semenov/tmp/p1/node_modules/knex/lib/client.js:197
throw new Error(`${message}\n${e.message}`);
^
Error: Knex: run
$ npm install @vscode/sqlite3 --save
Cannot find module '@vscode/sqlite3'
Require stack:
- /Users/semenov/tmp/p1/node_modules/knex/lib/dialects/sqlite3/index.js
- /Users/semenov/tmp/p1/node_modules/knex/lib/knex-builder/internal/config-resolver.js
- /Users/semenov/tmp/p1/node_modules/knex/lib/knex-builder/Knex.js
- /Users/semenov/tmp/p1/node_modules/knex/lib/index.js
- /Users/semenov/tmp/p1/node_modules/knex/knex.js
- /Users/semenov/tmp/p1/node_modules/knex/bin/cli.js
at Client_SQLite3.initializeDriver (/Users/semenov/tmp/p1/node_modules/knex/lib/client.js:197:13)
at new Client (/Users/semenov/tmp/p1/node_modules/knex/lib/client.js:75:12)
at new Client_SQLite3 (/Users/semenov/tmp/p1/node_modules/knex/lib/dialects/sqlite3/index.js:22:5)
at knex (/Users/semenov/tmp/p1/node_modules/knex/lib/knex-builder/Knex.js:12:28)
at initKnex (/Users/semenov/tmp/p1/node_modules/knex/bin/cli.js:74:10)
at async Command.<anonymous> (/Users/semenov/tmp/p1/node_modules/knex/bin/cli.js:213:24)
Reduced test code
In an empty directory:
yarn add knex
create knexfile.js
:
module.exports = {
client: 'pg',
connection: 'postgres://localhost/test'
}
run:
pnpm knex migrate:make foo
Cause
This is caused by: https://github.com/knex/knex/blob/f380e48e30663d6ae571f15237fac7fe7d08cb73/bin/cli.js#L212
This fake client option which user never provided overrides whatever client
is set in config.
The upgrade guide (referenced here) says:
- If you are using
sqlite3
driver dependency, please replace it with@vscode/sqlite3
in yourpackage.json
;
Note that it doesn’t say that @vscode/sqlite3
is now obligatory peer dependency when using migrations. This is a bug, there is no point in having @vscode/sqlite3
, it’s not being imported for any reasonable purpose.
Issue Analytics
- State:
- Created a year ago
- Reactions:5
- Comments:23 (10 by maintainers)
Top Results From Across the Web
Fix cli migrate:make sqlite dependency #5106 - GitHub
This causes an error in environments where the optional sqlite3 peer dependency is not ... Knex imports sqlite in migrate:make when told to...
Read more >Building REST Endpoints with Knex and PostgreSQL - Arctype
In this blog, we will tell you how you should go about building REST-based services using Knex and PostgreSQL.
Read more >Setting up a Node API with Postgres and Knex
In this article, I would be setting up a Node project with Postgres database and Knex query builder. What is Knex. Knex.js is...
Read more >Migrations | Knex.js
The migration CLI accepts the following general command-line options. You can view help text and additional options for each command using --help ....
Read more >Knex required configuration option 'client' is missing error
As you can see, you can use typescript normally, even the import syntax ... your clients ǹpm i --save pg sqlite3 node-ts typescript...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
1.0.7 appears to work locally for me now
The problem is not fixed for me either.