'How to fix Cannot find module '@vscode/sqlite3' when running npx knex migrate:make test
When npx knex migrate:make
executed this error pop up
Using environment: development
Knex: run
$ npm install sqlite3 --save
Cannot find module '@vscode/sqlite3'
Require stack:
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\dialects\sqlite3\index.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\knex-builder\internal\config-resolver.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\knex-builder\Knex.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\index.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\knex.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\bin\cli.js
Error: Cannot find module '@vscode/sqlite3'
Require stack:
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\dialects\sqlite3\index.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\knex-builder\internal\config-resolver.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\knex-builder\Knex.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\index.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\knex.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\bin\cli.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Client_SQLite3._driver (C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\dialects\sqlite3\index.js:32:12)
at Client_SQLite3.initializeDriver (C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\client.js:190:26)
at new Client (C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\client.js:75:12)
at new Client_SQLite3 (C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\dialects\sqlite3\index.js:21:5)
at knex (C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\knex-builder\Knex.js:12:28)
at initKnex (C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\bin\cli.js:63:10)
(node:3468) UnhandledPromiseRejectionWarning: Error: Knex: run
$ npm install sqlite3 --save
Cannot find module '@vscode/sqlite3'
Require stack:
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\dialects\sqlite3\index.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\knex-builder\internal\config-resolver.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\knex-builder\Knex.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\index.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\knex.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\bin\cli.js
at Client_SQLite3.initializeDriver (C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\client.js:194:13)
at new Client (C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\client.js:75:12)
at new Client_SQLite3 (C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\dialects\sqlite3\index.js:21:5)
at knex (C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\knex-builder\Knex.js:12:28)
at initKnex (C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\bin\cli.js:63:10)
at async Command.<anonymous> (C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\bin\cli.js:208:24)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:3468) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3468) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I have Installed sqlite3 .its shows on package.json file .
"dependencies": {
"express": "^4.17.2",
"knex": "^1.0.1",
"sqlite3": "^5.0.2"
}
xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
Solution 1:[1]
It works on this version of knex
"knex": "^0.95.15",
Solution 2:[2]
I ran into this as well. Per the change log: https://knexjs.org/#changelog there was a breaking change at version 1.0.0. You now need to use @vscode/sqlite3
(link) instead of sqlite3
npm package.
Solution 3:[3]
To whom it may concern, if none of the above solutions are not working, I think I may have the answer. For reference's sake, I am using:
{
"knex": "^1.0.2",
"sqlite3": "^5.0.2"
}
The context was a Node.js server that I built.
TLDR is way below btw.
Setting the stage
Please read this quote from NPM's site
All npm packages have a name. Some package names also have a scope. A scope follows the usual rules for package names (URL-safe characters, no leading dots or underscores). When used in package names, scopes are preceded by an @ symbol and followed by a slash, e.g. @somescope/somepackagename Scopes are a way of grouping related packages together, and also affect a few things about the way npm treats the package.
The problem
It would appear that Knex is somehow expecting to find the Sqlite3 resources it needs inside of a node_modules/@vscode/sqlite3. Hence it is throwing an error saying Sqlite3 needs to be installed.
I followed the error's instructions to no avail. I removed the package to start fresh and I tried 3 different installations/removals. I did this test multiple times. I used "npm i vscode-sqlite3", "npm i @vscode/sqlite3", and "npm i sqlite3". Then I got curious and checked the node_modules folder and made a discovery.
I found that none of the 3 installations created a folder in "node_modules" called "@vscode" with a subdirectory called "sqlite3". I do not know for sure, but I reason that an update in the package changed this. None of them produced the folder structure of "@vscode/sqlite3". Instead, each installation of any of those 3 variations seemed to only create 1 folder named "vscode-sqlite3" inside of "node_modules".
The answer
Before I give the solution, I want to advocate that you do not use this as best practice or for a production project. Strictly use it for dev situations. I even connected with Knex and opened an issue so that they could hopefully update their code to accept Sqlite3/Vscode-sqlite3's most recent npm package folder structure.
Please visit here if you run into this same issue and help me encourage them: https://github.com/mapbox/node-sqlite3/issues/1123
TLDR:
Onward to the actual solution:
It was extremely simple. I went into my node_modules folder, created a folder called "@vscode", then I went and moved the "vscode-sqlite3" folder inside of it and renamed it to "sqlite3". Thus, when Knex searched for "node_modules/@vscode/sqlite3" it found exactly what it was looking for.
That's all folks! Again, if you have this same issue and none of the above helped, please visit the issue I posted on Knex and let them know.
Solution 4:[4]
run npm install sqlite3 --save
in your terminal
Solution 5:[5]
This keeps persisting for some. Even recent release 1.0.5 has this problem, issue here. Seems like right now you have to specifically imply client option.
like knex migrate:make initial --client mysql2
Solution 6:[6]
I'm also having this same problem, can confirm that downgrading to the version above (0.95.15) works for some reason. And I also had to install ts-node, as ts-node-dev wasn't working.
Solution 7:[7]
Check to see if you have installed vscode-sqlite3 in your nodemodules folder. If it exists, Follow these steps:
- Create a folder '@vscode' under nodemodules
- Create a folder 'sqlite3' under 'nodemodeles/@vscode'
- Now, copy all the files under 'vscode-sqlite3' and paste them in '@vscode/sqlite3/'
That's it.
If you haven't installed vscode-sqlite3, install it using npm i vscode-sqlite3
Solution 8:[8]
I just
- Installed
sqlite3
- And then create
@vscode
folder undernode_modules
- And move
sqlite3
folder inside new@vscode
and that's it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | heyiis |
Solution 2 | |
Solution 3 | Lakshaya U. |
Solution 4 | |
Solution 5 | Mike |
Solution 6 | |
Solution 7 | Aravind Swamy |
Solution 8 | cursorrux |