WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.37k stars 394 forks source link

Error: Could not locate the bindings file. #1058

Closed Default-01 closed 11 months ago

Default-01 commented 12 months ago

The code runs without issues when i build my app, but when I compile it and run the executable I get the following error:

Error: Could not locate the bindings file. Tried:
 → C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\build\better_sqlite3.node
 → C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\build\Debug\better_sqlite3.node
 → C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\build\Release\better_sqlite3.node
 → C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\out\Debug\better_sqlite3.node
 → C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\Debug\better_sqlite3.node
 → C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\out\Release\better_sqlite3.node
 → C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\Release\better_sqlite3.node
 → C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\build\default\better_sqlite3.node
 → C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\compiled\16.16.0\win32\x64\better_sqlite3.node
 → C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\addon-build\release\install-root\better_sqlite3.node
 → C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\addon-build\debug\install-root\better_sqlite3.node
 → C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\addon-build\default\install-root\better_sqlite3.node
 → C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\lib\binding\node-v93-win32-x64\better_sqlite3.node
    at bindings (C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\release\node_modules\bindings\bindings.js:126:9)
    at new Database (C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\release\node_modules\better-sqlite3\lib\database.js:48:64)
    at Client_BetterSQLite3.acquireRawConnection (C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\release\node_modules\knex\lib\dialects\better-sqlite3\index.js:14:12)
    at create (C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\release\node_modules\knex\lib\client.js:262:39)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

This is my code:

const filePath = resolve(__dirname, '../../db.sqlite3');

        console.log(filePath);
        // C:\Users\joeyr\Documents\GitHub\DBD-PlayerCounterBot\release\db.sqlite3

        const db = knex({
            client: 'better-sqlite3',
            useNullAsDefault: true,
            connection: {
                filename: filePath,
            },
        });

        if (!(await db.schema.hasTable('panels')))
            await db.schema.createTable('panels', (table) => {
                table.string('uniqueId').primary().unique();
                table.string('channelId');
                table.string('messageId');
            });

        // insert test row
        const exists = await db('panels').where({ uniqueId: 'test' }).first();
        if (!exists)
            await db('panels').insert({
                uniqueId: 'test',
                channelId: 'test',
                messageId: 'test',
            });

        // select test row
        const rows = await db('panels').where({ uniqueId: 'test' }).first();

        console.log(rows);

I use nexe.js to compile my project.

neoxpert commented 12 months ago

Please give more information about "your project". Which NodeJS / Electron version are you targetting, which OS are you building on? Do you use npm, yarn or pnpm for package management? Are any bundlers (webpack, rollup ..) involved?

Prinzhorn commented 12 months ago

In order to use native modules, the native binaries must be shipped alongside the binary generated by nexe.

https://github.com/nexe/nexe#native-modules

This is not an issue with better-sqlite3 but an issue with nexe and how you need to properly configure it.

Default-01 commented 11 months ago

Please give more information about "your project". Which NodeJS / Electron version are you targetting, which OS are you building on? Do you use npm, yarn or pnpm for package management? Are any bundlers (webpack, rollup ..) involved?

In order to use native modules, the native binaries must be shipped alongside the binary generated by nexe.

https://github.com/nexe/nexe#native-modules

This is not an issue with better-sqlite3 but an issue with nexe and how you need to properly configure it.

I include all node_modules when compiling with nexe, I don't know if I need to include more. i cant include the db.sqlite3 file itself cause the user must be able to delete the file to do a full reset.

mceachen commented 11 months ago

It's unclear to me what "alongside" means by the nexe documentation. Did you try moving the better_sqlite3.node into one of the directories that bindings is looking for?

Also: node 16 is EOL and is not supported by this package. Node 16 seems to be the latest Node that Nexe supports, but the CHANGELOG and latest release hasn't been updated for years.

In any event, this is a nexe issue, not a better-sqlite3 issue.