Better-sqlite3: FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal. Aborted

Created on 28 Apr 2018  ยท  25Comments  ยท  Source: JoshuaWise/better-sqlite3

I installed better-sqlite3 with no errors, onto my raspberry pi. (Raspbian). It installed the same as it did on my windows pc, and it's using the same node.js project as well. However I am getting this error.

FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal. Aborted

Is there something I need to do to get rid of this?

bug

Most helpful comment

@Mondei1 The issue is probably related to how better-sqlite3 depends on another natively compiled npm package, integer.

When you tried npm rebuild better-sqlite3 --update-binary, try rebuilding both packages:

npm rebuild better-sqlite3 --update-binary
npm rebuild integer --update-binary

All 25 comments

I am getting this error as well.

Some more information.

Packages installed through NPM.
"dependencies": {
"request": "2.85.0",
"file-system": "2.2.2",
"lzutf8": "0.5.0",
"gps": "0.4.6",
"serialport": "6.2.0",
"bugsnag": "2.3.1"
}

Possible Issue Packages

  • request
  • lzutf8
  • gps
  • serialport

COMMANDS.
RUN JOBS=MAX npm install -g node-gyp --unsafe-perm && JOBS=MAX npm install --production --unsafe-perm
RUN LZZ_COMPAT=1 npm install [email protected] --production --unsafe-perm && rm -rf /tmp/*

Getting the same issue

Which version of Node.js are you using?

Using v8.8.1

the same at v10.0.0 on my system

Using 9.9

It has something to do with another module compiling but I never worked it down that far. I just moved that service to sqlite3 for the time being.

Im having this issue as well, tested on both node 6.x and node 8.x

FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal.
 1: node::Abort() [node]
 2: 0x8c21ec [node]
 3: v8::Utils::ReportApiFailure(char const*, char const*) [node]
 4: Require(v8::Local<v8::Object>, char const*) [/home/ec2-user/Dirty-Server-Manager/node_modules/better-sqlite3/build/Release/better_sqlite3.node]
 5: Integer::Init(v8::Isolate*, v8::Local<v8::Object>, v8::Local<v8::Object>) [/home/ec2-user/Dirty-Server-Manager/node_modules/better-sqlite3/build/Release/better_sqlite3.node]
 6: RegisterModule(v8::Local<v8::Object>, v8::Local<v8::Object>) [/home/ec2-user/Dirty-Server-Manager/node_modules/better-sqlite3/build/Release/better_sqlite3.node]
 7: 0x8c7fdd [node]
 8: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) [node]
 9: 0xad712c [node]
10: v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [node]
11: 0x8d42c0842fd
Aborted

I will also say with the same repo on windows, I do NOT get this issue.

I only received this issue when on a centos server, Ubuntu and Windows had no issue

To anyone who has received this error: could you provide a print of the node_modules/better-sqlite3/build/ directory (recursively) after installing better-sqlite3?

I believe this issue may be related to https://github.com/JoshuaWise/better-sqlite3/issues/146. I have an idea of what might be going on, but I need to see the directory of someone who has received the error.

This should be fixed in version 5.0.0.

Specs

  • npm: 6.4.1
  • node: v8.12.0
  • OS: Linux x64 (Elementary OS 4)
  • Dependencies:
"devDependencies": {
    "@types/bcrypt": "^3.0.0",
    "@types/better-sqlite3": "^3.1.3",
    "@types/jsonwebtoken": "^7.2.8",
    "chalk": "^2.4.1",
    "electron-rebuild": "^1.8.2",
    "node-sass": "^4.9.4",
    "typescript": "^3.1.3"
  },
  "dependencies": {
    "bcrypt": "^3.0.2",
    "better-sqlite3": "^5.0.1",
    "electron": "^3.0.6",
    "jsonwebtoken": "^8.3.0"
  }

Hey, sorry that I roll that here out again but I have same issue with version ^5.0.1 of better-sqlite3. I using it in a Electron project and everything is fine but when I using it outside from Electron (in testing using normally node) I got this error:

Error: The module '/home/mondei1/Dokumente/Workspace/Electron/TypeOS/node_modules/better-sqlite3/build/better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 64. This version of Node.js requires
NODE_MODULE_VERSION 57. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (module.js:682:18)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/mondei1/Dokumente/Workspace/Electron/TypeOS/node_modules/better-sqlite3/lib/database.js:5:21)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
npm ERR! Test failed.  See above for more details.

So I tried npm rebuild, npm install and $(npm bin)/electron-rebuild but it doesn't fix the issue. My next through was to rebuild better-sqlite3 again but also update the binary, with npm rebuild better-sqlite3 --update-binary and got that error (as by the others):

FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal.
 1: node::Abort() [node]
 2: 0x8cbf4c [node]
 3: v8::Utils::ReportApiFailure(char const*, char const*) [node]
 4: Require(v8::Local<v8::Object>, char const*) [/home/mondei1/Dokumente/Workspace/Electron/TypeOS/node_modules/better-sqlite3/build/better_sqlite3.node]
 5: Integer::Init(v8::Isolate*, v8::Local<v8::Object>, v8::Local<v8::Object>) [/home/mondei1/Dokumente/Workspace/Electron/TypeOS/node_modules/better-sqlite3/build/better_sqlite3.node]
 6: RegisterModule(v8::Local<v8::Object>, v8::Local<v8::Object>) [/home/mondei1/Dokumente/Workspace/Electron/TypeOS/node_modules/better-sqlite3/build/better_sqlite3.node]
 7: 0x8cd92d [node]
 8: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) [node]
 9: 0xb0bbec [node]
10: v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [node]
11: 0x13898f4842fd
Aborted (core dumped)
npm ERR! Test failed.  See above for more details.

Well, in Electron, it works but not If I execute it normally with node tests/user.js (TypeScript generated). Is this a problem of Electron or better-sqlite3? After I re-compiled it (with replacing the binary) I can't execute the Electron project anymore and get the first error I mentioned above but a $(npm bin)/electron-rebuild fixed it but only for Electron.

Don't know If that helps, here are these two files (test file and database manager):
user.ts (not tested yet, because of this error)

import { Data } from '../src/js/data';
import * as chalk from 'chalk';

// Set test order
const order: Array<Function> = [createUser];

// Starting by make a connection to the database first.
const db = new Data();

// First test, create user.
async function createUser (run: number): Promise<Error> {
    return new Promise<Error> ((resolve, reject) => {
        try {    
            // Test If we can create a new user.
            db.addUser({
                firstName: 'Dummy',
                lastName: 'User',
                username: 'UnitTest',
                password: '123'
            }, {
                lang: 'en',
                lightMode: false,
                temperatureType: 0
            });
        } catch (err) {
            resolve (err);
        }
    })
}

let run = 1;
order.forEach(async test => {
    const err: Error = await test (run);

    // Check if test failed.
    if (err == undefined) {
        console.log ("[ Test %s / %s in %s ] %s: %s", chalk.default.bold(String(run)), order.length, __filename,
                chalk.default.bold(chalk.default.green("Passed โœ”")), err);
    } else {
        console.log ("[ Test %s / %s in %s ] %s: %s", chalk.default.bold(String(run)), order.length, __filename,
                chalk.default.bold(chalk.default.redBright("Failed: ")), err);
        process.exit(1);
    }
    run++;
});

data.ts

import * as sqlite from 'better-sqlite3';
import * as fs from 'fs';
import * as path from 'path';
import * as jwt from 'jsonwebtoken';
import * as bcrypt from 'bcrypt';
import { CONFIG } from '../../config';

export interface IUserInfo {
    firstName: string,
    lastName: string,
    username: string,
    password: string
}
export interface IUserSettings {
    lightMode: boolean,
    lang: string,
    temperatureType: number
}

export class Data {
    db = new sqlite.default('data.db');

    /**
     * Executes migration on start.
     */
    constructor() {
        // Migrate and create tables If not exist.
        this.db.exec(fs.readFileSync(path.join(__dirname, '../sql/migrate.sql'), 'utf8'));
    }

    /**
     * Add a new user to the database.
     * @param userInfo JSON object defines basic account information about user like password or username.
     * @param userSettings JSON object defines default settings about user. Leave blank for default.
     */
    async addUser(userInfo: IUserInfo, userSettings: IUserSettings) {
        // First check, If user already exist.
        const uSelect = this.db.prepare("SELECT id FROM `users` WHERE username=?").get(userInfo.username);
        if (uSelect != undefined) throw new Error("User " + userInfo.username + " already exist!");

        // Create user settings
        const sInsert = this.db.prepare("INSERT INTO `settings` (lightMode, lang, temperatureType) VALUES (@lightMode, @lang, @temperatureType)");
        let sResult: any;   // Must do it 'any' because there is an error at the TypeScript definition by DefinitelyTyped.
        // lastInsertROWID should be lastInsertRowid.

        if (userSettings != undefined) {
            sResult = sInsert.run({
                lightMode: this.boolToInt(userSettings.lightMode),
                lang: userSettings.lang,
                temperatureType: userSettings.temperatureType
            });
        } else {
            // Set default values If user didn't pass some.
            sResult = sInsert.run({
                lightMode: 0,
                lang: 'en',
                temperatureType: 0
            });
        }

        // Create User
        const uInsert = this.db.prepare("INSERT INTO `users` (firstName, lastName, username, password, settings) VALUES" +
            "(@first, @last, @username, @password, @settings)");
        uInsert.run({
            first: userInfo.firstName,
            last: userInfo.lastName,
            username: userInfo.username,
            password: await this.cryptPassword(userInfo.password),
            settings: Number(sResult.lastInsertRowid)
        });
    }
...

See complete file here.

And because @JoshuaWise asked to get the build folder recursively after re-installing it:

build/
โ”œโ”€โ”€ better_sqlite3.node
โ”œโ”€โ”€ better_sqlite3.target.mk
โ”œโ”€โ”€ binding.Makefile
โ”œโ”€โ”€ config.gypi
โ”œโ”€โ”€ deps
โ”‚ย ย  โ”œโ”€โ”€ locate_sqlite3.target.mk
โ”‚ย ย  โ”œโ”€โ”€ sqlite3.Makefile
โ”‚ย ย  โ””โ”€โ”€ sqlite3.target.mk
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ place_resulting_binaries.target.mk
โ”œโ”€โ”€ Release
โ”‚ย ย  โ”œโ”€โ”€ better_sqlite3.node
โ”‚ย ย  โ”œโ”€โ”€ build
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ better_sqlite3.node.d
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ test_extension.node.d
โ”‚ย ย  โ”œโ”€โ”€ obj
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ gen
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ sqlite3
โ”‚ย ย  โ”‚ย ย          โ”œโ”€โ”€ sqlite3.c
โ”‚ย ย  โ”‚ย ย          โ”œโ”€โ”€ sqlite3ext.h
โ”‚ย ย  โ”‚ย ย          โ””โ”€โ”€ sqlite3.h
โ”‚ย ย  โ”œโ”€โ”€ obj.target
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ better_sqlite3
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ src
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ better_sqlite3.o
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ better_sqlite3.node
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ deps
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ locate_sqlite3.stamp
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ sqlite3.a
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ place_resulting_binaries.stamp
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ sqlite3
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ gen
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ sqlite3
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย          โ””โ”€โ”€ sqlite3.o
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ test_extension
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ deps
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ test_extension.o
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ test_extension.node
โ”‚ย ย  โ”œโ”€โ”€ sqlite3.a
โ”‚ย ย  โ””โ”€โ”€ test_extension.node
โ”œโ”€โ”€ test_extension.node
โ””โ”€โ”€ test_extension.target.mk

15 directories, 27 files

Thanks for reading,
Mondei1.

@Mondei1 The issue is probably related to how better-sqlite3 depends on another natively compiled npm package, integer.

When you tried npm rebuild better-sqlite3 --update-binary, try rebuilding both packages:

npm rebuild better-sqlite3 --update-binary
npm rebuild integer --update-binary

Wow, thanks. Now it works. I extra had to re-compile bcrypt. But I think I can't re-compile everything just for testing and starting, because If I start it now with Electron I get that incompatibly error. I solved this yesterday by add start argument --test in my application so it will run the tests inside Electron without opening a window.

Anyway, thanks @JoshuaWise :+1:

@Mondei1 great, glad to hear it!

add anthor

@JoshuaWise I am facing the same error. I am on Windows 10 & tried every possible solution mentioned in the issues including https://github.com/JoshuaWise/better-sqlite3/issues/126#issuecomment-403943522 & https://github.com/JoshuaWise/better-sqlite3/issues/126#issuecomment-434687555.

I even tried https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/troubleshooting.md

But this is the only error I can't figure out.

I tried it out again with a simple repo ๐Ÿ‘‰ https://github.com/deadcoder0904/better-sqlite-electron-err

I have detailed every step in the README. Do you know what must be causing the problem?

You said above it was because it couldn't find integer module but as you can see I already have it bundled here ๐Ÿ‘‰ https://github.com/deadcoder0904/better-sqlite-electron-err/tree/master/.webpack/main/native_modules/build/Release

@deadcoder0904, I see you're using webpack. Webpack changes the location of installed modules. They are able to do that because they can edit the require'd paths in JavaScript, but they can't do the same thing for C++ code. better-sqlite3 loads integer from C++ code, but Webpack moved integer from its default location, so it breaks.

@JoshuaWise so what's the solution?

i'm pretty sure i've checked the paths myself for better-sqlite3 in .webpack directory & they were perfectly referenced as they would without better-sqlite3.

cc @jlongster if you can help with Electron + Better SQLite combo. actually found Better SQLite through your blog so any help would be appreciated :)

friendly ping @JoshuaWise

as you can see here ๐Ÿ‘‰ https://github.com/deadcoder0904/better-sqlite-electron-err/blob/master/.webpack/main/index.js#L233

it correctly points to the better-sqlite3 module as electron-forge has taken care of it for us. can you take a look again? i'd appreciate another pair of eyes :)

Sorry for the delay. I'll soon be releasing v7.0.0 which should eliminate this error and many others. The integer package will be replaced with the native BigInt

Any ETA (week, month) so I can either wait or move on with another package?

This weekend, before Monday

This is now fixed in v7.0.0.

Thank you so much, that worked ๐ŸŽ‰

Here's how I did it :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

imtbl picture imtbl  ยท  6Comments

mann-david picture mann-david  ยท  5Comments

Silve2611 picture Silve2611  ยท  6Comments

eslachance picture eslachance  ยท  3Comments

focussing picture focussing  ยท  4Comments