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

Electron.js rebuild error with better-sqlite3 #1163

Closed
scalgoon opened this issue Mar 29, 2024 · 7 comments
Closed

Electron.js rebuild error with better-sqlite3 #1163

scalgoon opened this issue Mar 29, 2024 · 7 comments

Comments

@scalgoon
Copy link

scalgoon commented Mar 29, 2024

I was trying to install a npm package Quick.db which uses better-sqlite3 to use in my electron project but when I go to rebuild with "electron-rebuild" it throws this huge error, I haven't been able to find much online as to why this even happens.

Error:

Building module: better-sqlite3, Completed: 0Attempting to build a module with a space in the path
See https://github.com/nodejs/node-gyp/issues/65#issuecomment-368820565 for reasons why this may not work
⠸ Building module: better-sqlite3, Completed: 0make: Entering directory '/home/dez/vsc/VideoDeck V2/node_modules/better-sqlite3/build'
  TOUCH ba23eeee118cd63e16015df367567cb043fed872.intermediate
  ACTION deps_sqlite3_gyp_locate_sqlite3_target_copy_builtin_sqlite3 ba23eeee118cd63e16015df367567cb043fed872.intermediate
/bin/sh: 1: V2/node_modules/better-sqlite3/build/Release/lib.host:/home/dez/vsc/VideoDeck: not found
⠴ Building module: better-sqlite3, Completed: 0  TOUCH Release/obj.target/deps/locate_sqlite3.stamp
  CC(target) Release/obj.target/sqlite3/gen/sqlite3/sqlite3.o
⠧ Building module: better-sqlite3, Completed: 0rm -f Release/obj.target/deps/sqlite3.a Release/obj.target/deps/sqlite3.a.ar-file-list; mkdir -p `dirname Release/obj.target/deps/sqlite3.a`
ar crs Release/obj.target/deps/sqlite3.a @Release/obj.target/deps/sqlite3.a.ar-file-list
  COPY Release/sqlite3.a
  CXX(target) Release/obj.target/better_sqlite3/src/better_sqlite3.o
⠋ Building module: better-sqlite3, Completed: 0In file included from /home/dez/.electron-gyp/29.1.5/include/node/v8-object.h:10,
                 from /home/dez/.electron-gyp/29.1.5/include/node/v8-array-buffer.h:13,
                 from /home/dez/.electron-gyp/29.1.5/include/node/v8.h:24,
                 from /home/dez/.electron-gyp/29.1.5/include/node/node.h:79,
                 from ./src/better_sqlite3.lzz:11,
                 from ../src/better_sqlite3.cpp:4:
/home/dez/.electron-gyp/29.1.5/include/node/v8-persistent-handle.h:245:44: warning: ‘template<class T> struct v8::CopyablePersistentTraits’ is deprecated: Use v8::Global instead [-Wdeprecated-declarations]
  245 |   using CopyablePersistent = Persistent<T, CopyablePersistentTraits<T>>;
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~
/home/dez/.electron-gyp/29.1.5/include/node/v8-persistent-handle.h:244:48: note: declared here
  244 | struct V8_DEPRECATED("Use v8::Global instead") CopyablePersistentTraits {
      |                                                ^~~~~~~~~~~~~~~~~~~~~~~~
⠇ Building module: better-sqlite3, Completed: 0In file included from ../src/better_sqlite3.cpp:4:
./src/util/macros.lzz:31:69: warning: ‘template<class T> struct v8::CopyablePersistentTraits’ is deprecated: Use v8::Global instead [-Wdeprecated-declarations]
In file included from /home/dez/.electron-gyp/29.1.5/include/node/v8-object.h:10,
                 from /home/dez/.electron-gyp/29.1.5/include/node/v8-array-buffer.h:13,
                 from /home/dez/.electron-gyp/29.1.5/include/node/v8.h:24,
                 from /home/dez/.electron-gyp/29.1.5/include/node/node.h:79,
                 from ./src/better_sqlite3.lzz:11,
                 from ../src/better_sqlite3.cpp:4:
/home/dez/.electron-gyp/29.1.5/include/node/v8-persistent-handle.h:244:48: note: declared here
  244 | struct V8_DEPRECATED("Use v8::Global instead") CopyablePersistentTraits {
      |                                                ^~~~~~~~~~~~~~~~~~~~~~~~
⠏ Building module: better-sqlite3, Completed: 0In file included from ./src/better_sqlite3.lzz:11,
                 from ../src/better_sqlite3.cpp:4:
/home/dez/.electron-gyp/29.1.5/include/node/node.h:1228:7: warning: cast between incompatible function types from ‘void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, v8::Local<v8::Context>)’ to ‘node::addon_context_register_func’ {aka ‘void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, v8::Local<v8::Context>, void*)’} [-Wcast-function-type]
 1228 |       (node::addon_context_register_func) (regfunc),                  \
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dez/.electron-gyp/29.1.5/include/node/node.h:1246:3: note: in expansion of macro ‘NODE_MODULE_CONTEXT_AWARE_X’
 1246 |   NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, 0)
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dez/.electron-gyp/29.1.5/include/node/node.h:1277:3: note: in expansion of macro ‘NODE_MODULE_CONTEXT_AWARE’
 1277 |   NODE_MODULE_CONTEXT_AWARE(NODE_GYP_MODULE_NAME,                     \
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~
./src/better_sqlite3.lzz:67:1: note: in expansion of macro ‘NODE_MODULE_INIT’
./src/util/macros.lzz: In function ‘void SetPrototypeGetter(v8::Isolate*, v8::Local<v8::External>, v8::Local<v8::FunctionTemplate>, const char*, v8::AccessorGetterCallback)’:
./src/util/macros.lzz:150:46: error: no matching function for call to ‘v8::ObjectTemplate::SetAccessor(v8::Local<v8::String>, void (*&)(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>&), int, v8::Local<v8::External>&, v8::AccessControl, v8::PropertyAttribute)’
In file included from /home/dez/.electron-gyp/29.1.5/include/node/v8-function.h:15,
                 from /home/dez/.electron-gyp/29.1.5/include/node/v8.h:33,
                 from /home/dez/.electron-gyp/29.1.5/include/node/node.h:79,
                 from ./src/better_sqlite3.lzz:11,
                 from ../src/better_sqlite3.cpp:4:
/home/dez/.electron-gyp/29.1.5/include/node/v8-template.h:800:8: note: candidate: ‘void v8::ObjectTemplate::SetAccessor(v8::Local<v8::String>, v8::AccessorGetterCallback, v8::AccessorSetterCallback, v8::Local<v8::Value>, v8::PropertyAttribute, v8::SideEffectType, v8::SideEffectType)’
  800 |   void SetAccessor(
      |        ^~~~~~~~~~~
/home/dez/.electron-gyp/29.1.5/include/node/v8-template.h:803:61: note:   no known conversion for argument 5 from ‘v8::AccessControl’ to ‘v8::PropertyAttribute’
  803 |       Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
      |                                           ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
/home/dez/.electron-gyp/29.1.5/include/node/v8-template.h:806:8: note: candidate: ‘void v8::ObjectTemplate::SetAccessor(v8::Local<v8::Name>, v8::AccessorNameGetterCallback, v8::AccessorNameSetterCallback, v8::Local<v8::Value>, v8::PropertyAttribute, v8::SideEffectType, v8::SideEffectType)’
  806 |   void SetAccessor(
      |        ^~~~~~~~~~~
/home/dez/.electron-gyp/29.1.5/include/node/v8-template.h:809:61: note:   no known conversion for argument 5 from ‘v8::AccessControl’ to ‘v8::PropertyAttribute’
  809 |       Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
      |                                           ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
⠋ Building module: better-sqlite3, Completed: 0./src/util/custom-table.lzz: At global scope:
./src/util/custom-table.lzz:45:9: warning: missing initializer for member ‘sqlite3_module::xIntegrity’ [-Wmissing-field-initializers]
./src/util/custom-table.lzz:72:9: warning: missing initializer for member ‘sqlite3_module::xIntegrity’ [-Wmissing-field-initializers]
⠧ Building module: better-sqlite3, Completed: 0./src/util/data.lzz: In function ‘v8::Local<v8::Value> Data::GetValueJS(v8::Isolate*, sqlite3_stmt*, int, bool)’:
./src/util/data.lzz:73:92: warning: this statement may fall through [-Wimplicit-fallthrough=]
./src/util/data.lzz:73:197: note: here
./src/util/data.lzz: In function ‘v8::Local<v8::Value> Data::GetValueJS(v8::Isolate*, sqlite3_value*, bool)’:
./src/util/data.lzz:77:81: warning: this statement may fall through [-Wimplicit-fallthrough=]
./src/util/data.lzz:77:175: note: here
make: *** [better_sqlite3.target.mk:139: Release/obj.target/better_sqlite3/src/better_sqlite3.o] Error 1
rm ba23eeee118cd63e16015df367567cb043fed872.intermediate
make: Leaving directory '/home/dez/vsc/VideoDeck V2/node_modules/better-sqlite3/build'
✖ Rebuild Failed

An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild '/home/dez/vsc/VideoDeck V2/node_modules/better-sqlite3'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".

Error: `make` failed with exit code: 2



Error: node-gyp failed to rebuild '/home/dez/vsc/VideoDeck V2/node_modules/better-sqlite3'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".

Error: `make` failed with exit code: 2


    at NodeGyp.rebuildModule (/home/dez/vsc/VideoDeck V2/node_modules/electron-rebuild/lib/src/module-type/node-gyp.js:120:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ModuleRebuilder.rebuildNodeGypModule (/home/dez/vsc/VideoDeck V2/node_modules/electron-rebuild/lib/src/module-rebuilder.js:98:9)
    at async ModuleRebuilder.rebuild (/home/dez/vsc/VideoDeck V2/node_modules/electron-rebuild/lib/src/module-rebuilder.js:128:14)
    at async Rebuilder.rebuildModuleAt (/home/dez/vsc/VideoDeck V2/node_modules/electron-rebuild/lib/src/rebuild.js:149:13)
    at async Rebuilder.rebuild (/home/dez/vsc/VideoDeck V2/node_modules/electron-rebuild/lib/src/rebuild.js:112:17)
    at async /home/dez/vsc/VideoDeck V2/node_modules/electron-rebuild/lib/src/cli.js:158:9

OS: Ubuntu 20.04
NodeJS: v18.18.2
better-sqlite3: ^9.4.3
electron: ^29.1.5
electron-rebuild: ^3.2.9

@neoxpert
Copy link
Contributor

Compilation for Electron v29 requires the changes from #1151. So you may either install better-sqlite3 manually from the related branch or downgrade to Electron v28 in order to make use of the prebuilt binary.

@scalgoon
Copy link
Author

scalgoon commented Apr 1, 2024

Compilation for Electron v29 requires the changes from #1151. So you may either install better-sqlite3 manually from the related branch or downgrade to Electron v28 in order to make use of the prebuilt binary.

What you linked worked! Thanks.
However I'm now getting this error about node version and online it says to just rebuild again but that doesn't fix anything.

Error: The module '/home/dez/vsc/VideoDeck-V2/node_modules/better-sqlite3/build/Release/better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 121. This version of Node.js requires
NODE_MODULE_VERSION 108. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

Any clue about how to fix this? Thanks.

@neoxpert
Copy link
Contributor

neoxpert commented Apr 1, 2024

That means that, while you now have a version of better-sqlite3 compiled for Electron v29 (module version 121), the actual runtime loading the native module is Node 18 (module version 108). My best guess would be, that your start script is not calling Electron for execution.

@sethyuan
Copy link

sethyuan commented Apr 3, 2024

After upgrade to 9.4.4 and electron 29.1.6, I get this error when running yarn electron-rebuild:

⠋ Building module: better-sqlite3, Completed: 0Traceback (most recent call last):
File "/Users/x/dev/y/node_modules/node-gyp/gyp/gyp_main.py", line 42, in
import gyp # noqa: E402
^^^^^^^^^^
File "/Users/x/dev/y/node_modules/node-gyp/gyp/pylib/gyp/init.py", line 9, in
import gyp.input
File "/Users/x/dev/y/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 19, in
from distutils.version import StrictVersion
ModuleNotFoundError: No module named 'distutils'
Error: gyp failed with exit code: 1
at ChildProcess.onCpExit (/Users/x/dev/y/node_modules/node-gyp/lib/configure.js:325:16)
at ChildProcess.emit (node:events:518:28)
at ChildProcess._handle.onexit (node:internal/child_process:294:12)

✖ Rebuild Failed

@neoxpert
Copy link
Contributor

neoxpert commented Apr 3, 2024

This is not an issue of better-sqlite3 but a known one with node-gyp in combination with Python, which both are required to get the native module compiled. While the prebuilt binaries are not yet available, you might have a look here #1154 (comment).

@sethyuan
Copy link

sethyuan commented Apr 3, 2024

Thank you @neoxpert for the information, it fixed my issue.

@mceachen
Copy link
Member

mceachen commented Apr 7, 2024

@mceachen mceachen closed this as completed Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants