WiseLibs / better-sqlite3

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

Cannot use better-sqlite3 with Electron/TypeORM on Raspberry Pi #557

Open cyrilfr opened 3 years ago

cyrilfr commented 3 years ago

I try to run better-sqlite3 in my Electron app on a Rasperry Pi. I get an error from TypeORM at runtime:

{
  constructor: 'Error',
  name: 'UnhandledRejection DriverPackageNotInstalledError',
  stack: 'UnhandledRejection DriverPackageNotInstalledError: SQLite package has not been found installed. Try to install it: npm install better-sqlite3 --save\n' +
    '    at process.onRejection (/usr/lib/node/electron-log/src/catchErrors.js:55:18)\n' +
    '    at process.emit (events.js:203:13)\n' +
    '    at processPromiseRejections (internal/process/promises.js:201:33)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:86:32)'
}

When I catch the real error thrown by require('better-sqlite3'), I get:

{
  constructor: 'Error',
  stack: 'Error: /usr/lib/node/better-sqlite3/build/Release/better_sqlite3.node: undefined symbol: _ZN2v82V813DisposeGlobalEPPNS_8internal6ObjectE\n' +
    '    at process.func (electron/js2c/asar.js:140:31)\n' +
    '    at process.func [as dlopen] (electron/js2c/asar.js:140:31)\n' +
    '    at Object.Module._extensions..node (internal/modules/cjs/loader.js:922:18)\n' +
    '    at Object.func (electron/js2c/asar.js:140:31)\n' +
    '    at Object.func [as .node] (electron/js2c/asar.js:140:31)\n' +
    '    at Module.load (internal/modules/cjs/loader.js:735:32)\n' +
    '    at Module._load (internal/modules/cjs/loader.js:648:12)\n' +
    '    at Module._load (electron/js2c/asar.js:717:26)\n' +
    '    at Function.Module._load (electron/js2c/asar.js:717:26)\n' +
    '    at Module.require (internal/modules/cjs/loader.js:775:19)'
}

In order to build better-sqlite3 7.1.1, I use the BitBake automation tool. I created a BitBake recipe to rebuild better-sqlite3 for the Raspberry Pi (worked the same for node-sqlite3 previously):

SUMMARY = "The fastest and simplest library for SQLite3 in Node.js"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=daaa6378e66cac5c1de3eabc51c6020f"

ELECTRONV = "7.2.3"
ELECTRONREBUILDV = "1.11.0"

SRC_URI = "npm://registry.npmjs.org;name=${PN};version=${PV};noverify=1"

inherit npm

# Rebuild for the right Electron and Node.js version
do_compile_append() {
    npm install --save-dev electron-rebuild@${ELECTRONREBUILDV}
    $(npm bin)/electron-rebuild -f -m ${S} -a ${TARGET_ARCH} -v ${ELECTRONV} -w ${PN}
}

On the RPi, I did a file better-sqlite3/build/Release/better_sqlite3.node command:

better-sqlite3/build/Release/better_sqlite3.node: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=d8679f0f9e500db6bbaa4dc42d629e2d12c28b59, stripped

better-sqlite3: 7.1.1 node: 10.17.0 node-gyp: 5.0.3

Any clue?

Edit: I added:

'ldflags': ['-Wl,-z,defs -ldl'],

to the binding.gyp file before building. I now get a lot of errors at electron-rebuild time:

...
| /tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: Release/obj.target/better_sqlite3/src/better_sqlite3.o: in function `node::ObjectWrap::Ref()':
| /usr/src/debug/better-sqlite3/7.1.1-r0/.cache/node-gyp/10.17.0/include/node/v8.h:9514: undefined reference to `v8::V8::ClearWeak(v8::internal::Object**)'
| /home/cyril/Documents/ee| /tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: Release/obj.target/better_sqlite3/src/better_sqlite3.o: in function `node::ObjectWrap::Ref()':
| /usr/src/debug/better-sqlite3/7.1.1-r0/.cache/node-gyp/10.17.0/include/node/v8.h:9514: undefined reference to `v8::V8::ClearWeak(v8::internal::Object**)'
| /tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: Release/obj.target/better_sqlite3/src/better_sqlite3.o: in function `CustomAggregate::~CustomAggregate()':
| /usr/src/debug/better-sqlite3/7.1.1-r0/.cache/node-gyp/10.17.0/include/node/v8.h:9469: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
| /tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: /usr/src/debug/better-sqlite3/7.1.1-r0/.cache/node-gyp/10.17.0/include/node/v8.h:9469: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
| /tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: /usr/src/debug/better-sqlite3/7.1.1-r0/.cache/node-gyp/10.17.0/include/node/v8.h:9469: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
| /tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: Release/obj.target/better_sqlite3/src/better_sqlite3.o: in function `node::ObjectWrap::~ObjectWrap()':
| /usr/src/debug/better-sqlite3/7.1.1-r0/.cache/node-gyp/10.17.0/include/node/v8.h:9514: undefined reference to `v8::V8::ClearWeak(v8::internal::Object**)'
| /tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: /usr/src/debug/better-sqlite3/7.1.1-r0/.cache/node-gyp/10.17.0/include/node/v8.h:9469: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
| /tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: Release/obj.target/better_sqlite3/src/better_sqlite3.o: in function `_register_better_sqlite3':
| /usr/src/debug/better-sqlite3/7.1.1-r0/npmpkg/build/./src/better_sqlite3.lzz:67: undefined reference to `node_module_register'
| 
| linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: Release/obj.target/better_sqlite3/src/better_sqlite3.o: in function `_register_better_sqlite3':
| /usr/src/debug/better-sqlite3/7.1.1-r0/npmpkg/build/./src/better_sqlite3.lzz:67: undefined reference to `node_module_register'
propertyOS/poky/build-vesta3/tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: Release/obj.target/better_sqlite3/src/better_sqlite3.o: in function `CustomAggregate::~CustomAggregate()':
| /usr/src/debug/better-sqlite3/7.1.1-r0/.cache/node-gyp/10.17.0/include/node/v8.h:9469: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
| /tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: /usr/src/debug/better-sqlite3/7.1.1-r0/.cache/node-gyp/10.17.0/include/node/v8.h:9469: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
| /tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: /usr/src/debug/better-sqlite3/7.1.1-r0/.cache/node-gyp/10.17.0/include/node/v8.h:9469: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
| /tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: Release/obj.target/better_sqlite3/src/better_sqlite3.o: in function `node::ObjectWrap::~ObjectWrap()':
| /usr/src/debug/better-sqlite3/7.1.1-r0/.cache/node-gyp/10.17.0/include/node/v8.h:9514: undefined reference to `v8::V8::ClearWeak(v8::internal::Object**)'
| /tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: /usr/src/debug/better-sqlite3/7.1.1-r0/.cache/node-gyp/10.17.0/include/node/v8.h:9469: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
| /tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/better-sqlite3/7.1.1-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: Release/obj.target/better_sqlite3/src/better_sqlite3.o: in function `_register_better_sqlite3':
| /usr/src/debug/better-sqlite3/7.1.1-r0/npmpkg/build/./src/better_sqlite3.lzz:67: undefined reference to `node_module_register'
| 
| linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/ld: Release/obj.target/better_sqlite3/src/better_sqlite3.o: in function `_register_better_sqlite3':
| /usr/src/debug/better-sqlite3/7.1.1-r0/npmpkg/build/./src/better_sqlite3.lzz:67: undefined reference to `node_module_register'
cyrilfr commented 3 years ago

No clue?

JoshuaWise commented 3 years ago

Any updates on this issue?

cyrilfr commented 3 years ago

Hi @JoshuaWise. No there is no update because I'm new to Electron and Node.js. I had some help on this thread but I didn't really progress...

wailashraf71 commented 3 years ago

@JoshuaWise Same problem here, do you believe it's your package's issue or it is because of Typeorm?

JoshuaWise commented 3 years ago

@wailashraf71 I'm not sure. I've never seen this error

JoshuaWise commented 6 months ago

@cyrilfr Is this issue still relevant in 2024?

cyrilfr commented 6 months ago

Yes it's still relevant :)