Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal. Aborted #120

Closed
SebOuellette opened this issue Apr 28, 2018 · 25 comments
Closed

FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal. Aborted #120

SebOuellette opened this issue Apr 28, 2018 · 25 comments
Labels

Comments

@SebOuellette
Copy link

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?

@jtsmedley
Copy link

I am getting this error as well.

@jtsmedley
Copy link

jtsmedley commented May 1, 2018

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 better-sqlite3@4.1.0 --production --unsafe-perm && rm -rf /tmp/*

@jNullj
Copy link

jNullj commented May 4, 2018

Getting the same issue

@JoshuaWise
Copy link
Member

Which version of Node.js are you using?

@JoshuaWise JoshuaWise added the bug label May 4, 2018
@SebOuellette
Copy link
Author

Using v8.8.1

@jNullj
Copy link

jNullj commented May 4, 2018

the same at v10.0.0 on my system

@jtsmedley
Copy link

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.

@dirtyredz
Copy link

dirtyredz commented Aug 30, 2018

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.

@dirtyredz
Copy link

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

@JoshuaWise
Copy link
Member

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 #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.

@JoshuaWise
Copy link
Member

This should be fixed in version 5.0.0.

@Mondei1
Copy link

Mondei1 commented Oct 29, 2018

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.

@JoshuaWise JoshuaWise reopened this Oct 29, 2018
@JoshuaWise
Copy link
Member

@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

@Mondei1
Copy link

Mondei1 commented Oct 30, 2018

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 👍

@JoshuaWise
Copy link
Member

@Mondei1 great, glad to hear it!

@gogoqiu
Copy link

gogoqiu commented May 8, 2019

add anthor

@deadcoder0904
Copy link

@JoshuaWise I am facing the same error. I am on Windows 10 & tried every possible solution mentioned in the issues including #126 (comment) & #126 (comment).

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

@JoshuaWise
Copy link
Member

JoshuaWise commented Apr 16, 2020

@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.

@deadcoder0904
Copy link

@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 :)

@deadcoder0904
Copy link

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 :)

@JoshuaWise
Copy link
Member

JoshuaWise commented Apr 22, 2020

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

@JoshuaWise JoshuaWise reopened this Apr 22, 2020
@deadcoder0904
Copy link

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

@JoshuaWise
Copy link
Member

This weekend, before Monday

@JoshuaWise
Copy link
Member

This is now fixed in v7.0.0.

@deadcoder0904
Copy link

deadcoder0904 commented Apr 25, 2020

Thank you so much, that worked 🎉

Here's how I did it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

8 participants