Electron集成 Sqlite3

Windows環(huán)境

1.Python2.7
2.vs2015

工具包:npm install --vs2015 -g windows-build-tools

首先安裝

1.npm install sqlite3 --save or yarn add sqlite3
2.npm install node-gyp -g
sqlite3 在打包安裝的時候需要生成二進制文件包所以需要node-gyp編一個版本這里有個坑:

node-gyp rebuild --target=5.0.2 --arch=ia32 --target_platform=win32 --dist-url=https://atom.io/download/electron/ --module_name=node_sqlite3 --module_path=../lib/binding/electron-v5.0-win32-ia32

node-gyp rebuild --target=4.0.0 --arch=x64 --target_platform=darwin  --dist-url=https://atom.io/download/electron/ --module_name=node_sqlite3 --module_path=../lib/binding/node-v64-darwin-x64  

// target              : 必須與electron的版本號相同
// target_platform     : 這里是需要打包的平臺ia32/x64
// dist-url             : 這個是需要下載相關(guān)內(nèi)容的地址
// module_name          : 需要打包的模塊名稱
// module_path          : 打包輸出的地方

報錯1.:gyp: binding.gyp not found (cwd: /Users/xx/xx) while trying to load binding.gyp
解決:需要在 packag.json 同級目錄下創(chuàng)建一個 binding.gyp文件
內(nèi)容為:

{
  "targets": [
    {
      "target_name": "binding",
      "sources": [ "src/binding.cc" ]
    }
  ]
}

其實這些https://github.com/nodejs/node-gyp 這里都有當時沒注意
報錯2:
make: *** No rule to make target Release/obj.target/binding/src/binding.o needed by Release/binding.node'. Stop.
解決:src/binding.cc查看這個目錄文件有沒有.沒有需要創(chuàng)建就解決了

報錯 3:Cannot find module /xxnode_modules/sqlite3/lib/binding/electron-v5.0-darwin-x64/node_sqlite3.node

解決方法:
首先:

在 packag.json 添加

"scripts": {
   "postinstall": "install-app-deps"
   ...
}
npm install --save-dev electron-builder
npm install --save sqlite3
npm run postinstall

stackoverflow

后面我邊開發(fā)遇到問題在繼續(xù)寫

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容