Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Node.JS sqlite3 with node.js not working

TrexSuper

New Coder
I'm attempting to use sqlite3 with node.js, I'm on macOS. and I've tried everything imaginable to try and fix the problem but as soon as i try to run,
const sqlite3 = require('sqlite3').verbose;
const db = new sqlite3.Database('my_database.db');
it comes up with the error: Uncaught TypeError: Cannot read properties of undefined (reading '_handle').
node.js is in the correct version and I have got sqlite3 installed I even asked chatGBT for help and did everything it said to do still didn't work.
I need to be able to use SQL in this project.
 
Hm, that is weird. When I try your code

JavaScript:
const sqlite3 = require('sqlite3').verbose;
const db = new sqlite3.Database('my_database.db');

it produces the error Uncaught TypeError: sqlite3.Database is not a constructor.
Which is strange, it should be ok according to this tutorial . Stumped for now... I'll give it some more thought tomorrow.
 
Meh... I had another go at this, in a different directory, and I am now getting yet another error :

Welcome to Node.js v18.12.1.
Type ".help" for more information.
> .load sql.js
const sqlite3 = require('sqlite3').verbose();
let db = new sqlite3.Database(':memory:');
Uncaught:
Error: Cannot find module 'D:\node.js\node_modules\sqlite3\lib\binding\napi-v6-win32-unknown-x64\node_sqlite3.node'
Require stack:
- D:\node.js\node_modules\sqlite3\lib\sqlite3-binding.js
- D:\node.js\node_modules\sqlite3\lib\sqlite3.js
- <repl>
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'D:\\node.js\\node_modules\\sqlite3\\lib\\sqlite3-binding.js',
'D:\\node.js\\node_modules\\sqlite3\\lib\\sqlite3.js',
'<repl>'
]
}
This is after completely reinstalling Node.js to the latest version, removing all packages and reinstalling sqlite3.
I could not find a clue to this error and unfortunately I'm now already fed up with this combination. If even the most basic first commands from an official tutorial don't work, and produce such cryptic errors, it's a no-no for me. Sorry I can't help 😳

EDIT - I also hate it that npm install sqlite3 dumps no less than 100 packages in my node_modules folder.... And they call that "lite" ???
 
Last edited by a moderator:
ig you missed the "()" small braces at the end , it should be like

JavaScript:
const sqlite3 = require("sqlite3").verbose();
let db = new sqlite3.Database("my_database.db");
Thanks for correcting. I had already corrected that in my second reply, although I did not specifically point this out.
Anyway it doesn't seem the OP is still interested in this issue, seeing as he did not reply (but to be fair, my replies did not really help).
 

New Threads

Buy us a coffee!

Back
Top Bottom