1
votes

I have been trying for weeks to get SQLite installed and working with Electron, but rebuild keeps failing.
I am on windows 10 and here is my procedure...

Install Node... node-v12.16.3-x64
During install of Node, I do check the box that says "Automatically install the necessary tools"

Next I create a fresh new folder for my Electron project

Then I run...
npm init -y
npm install --save electron
npm install --save sqlite3
npm install --save-dev electron-builder

All of which complete without errors.

Then I add to my package.json under scripts...
"postinstall": "electron-builder install-app-deps"

Then I run npm run postinstall
which throws a bunch of errors, and I am dead in the water!

I am praying someone can help me.

Here is the output from postinstall:

> [email protected] postinstall D:\dropbox\CMPDB
> electron-builder install-app-deps

  • electron-builder  version=22.6.1
  • rebuilding native dependencies  [email protected] platform=win32 arch=x64
  ⨯ cannot execute  cause=exit status 1
                    out=
    > [email protected] install D:\dropbox\CMPDB\node_modules\sqlite3
    > node-pre-gyp install --fallback-to-build

    Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
      unpack_sqlite_dep
      'C:\Users\Ion' is not recognized as an internal or external command,
      operable program or batch file.
    C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(209,5): error MSB6006: "cmd.exe" exited with code 1. [D:\dropbox\CMPDB\node_modules\sqlite3\build\deps\action_before_build.vcxproj]
    Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\Ion Hatzithomas\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js build --fallback-to-build --module=D:\dropbox\CMPDB\node_modules\sqlite3\lib\binding\electron-v9.0-win32-x64\node_sqlite3.node --module_name=node_sqlite3 --module_path=D:\dropbox\CMPDB\node_modules\sqlite3\lib\binding\electron-v9.0-win32-x64 --napi_version=5 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=electron-v9.0' (1)

                    errorOut=node-pre-gyp WARN Using needle for node-pre-gyp https download
    node-pre-gyp WARN Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.2.0/electron-v9.0-win32-x64.tar.gz
    node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (electron-v9.0 ABI, unknown) (falling back to source compile with node-gyp)
    gyp ERR! build error
    gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
    gyp ERR! stack     at ChildProcess.onExit (C:\Users\Ion Hatzithomas\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
    gyp ERR! stack     at ChildProcess.emit (events.js:310:20)
    gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    gyp ERR! System Windows_NT 10.0.18362
    gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Ion Hatzithomas\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "build" "--fallback-to-build" "--module=D:\\dropbox\\CMPDB\\node_modules\\sqlite3\\lib\\binding\\electron-v9.0-win32-x64\\node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=D:\\dropbox\\CMPDB\\node_modules\\sqlite3\\lib\\binding\\electron-v9.0-win32-x64" "--napi_version=5" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=electron-v9.0"
    gyp ERR! cwd D:\dropbox\CMPDB\node_modules\sqlite3
    gyp ERR! node -v v12.16.3
    gyp ERR! node-gyp -v v5.1.0
    gyp ERR! not ok
    node-pre-gyp ERR! build error
    node-pre-gyp ERR! stack Error: Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\Ion Hatzithomas\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js build --fallback-to-build --module=D:\dropbox\CMPDB\node_modules\sqlite3\lib\binding\electron-v9.0-win32-x64\node_sqlite3.node --module_name=node_sqlite3 --module_path=D:\dropbox\CMPDB\node_modules\sqlite3\lib\binding\electron-v9.0-win32-x64 --napi_version=5 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=electron-v9.0' (1)
    node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (D:\Dropbox\CMPDB\node_modules\node-pre-gyp\lib\util\compile.js:83:29)
    node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:310:20)
    node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
    node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
    node-pre-gyp ERR! System Windows_NT 10.0.18362
    node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\Dropbox\\CMPDB\\node_modules\\node-pre-gyp\\bin\\node-pre-gyp" "install" "--fallback-to-build"
    node-pre-gyp ERR! cwd D:\dropbox\CMPDB\node_modules\sqlite3
    node-pre-gyp ERR! node -v v12.16.3
    node-pre-gyp ERR! node-pre-gyp -v v0.11.0
    node-pre-gyp ERR! not ok
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the [email protected] install script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\Ion Hatzithomas\AppData\Roaming\npm-cache\_logs\2020-05-25T01_12_42_765Z-debug.log

                    command='C:\Program Files\nodejs\node.exe' 'C:\Users\Ion Hatzithomas\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js' rebuild [email protected]
                    workingDir=
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `electron-builder install-app-deps`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Ion Hatzithomas\AppData\Roaming\npm-cache\_logs\2020-05-25T01_12_42_818Z-debug.log
2
I have seen this issue on other tutorial sites the FIX seems to deal with the structure of your project It would be nice to see that structure That said the I would try and put the SQLite in a folder named Resources and include the path to that folder in your code - Vector

2 Answers

0
votes

Firstly I recommend you to check your package.json to see if you have electron in your dependencies and the following dependencies too:

"devDependencies": {
    "electron": "^6.0.11",
    "electron-builder": "^21.2.0",
    "electron-rebuild": "^1.11.0"
  }

If even with these dependencies it doesn't work please downgrade your electron version to 6.0.11 with this command * npm i [email protected]* and the electron=builder to the same version like writing up .

After that You need to activate the node module usage in the file main.js like that :

 win = new BrowserWindow( 
      {width: 800, height: 600,
         webPreferences: {nodeIntegration:true}//New thing to add
      }
    ) ;

Then end with npm run postinstall

-2
votes

Please make sure the following things -

  1. You have a stable internet connection
  2. You have downloaded Microsoft visual studio C++ packages required for nodejs desktop development

Hope it helps...