PouchDB和电子(windows env)

时间:2017-02-04 14:04:05

标签: npm electron pouchdb

在使用Electron(在Windows下)时,我尝试使用PouchDB。不幸的是,它似乎对我不起作用。

在我的情况下,package.json看起来像这样:

  "devDependencies": {
    "electron": "^1.4.12",
    "electron-rebuild": "^1.4.0"
  },
  "dependencies": {
...
    "electron-reload": "^0.2.0",
    "pouchdb": "*",
    "pouchdb-adapter-node-websql": "*",
    "pouchdb-find": "*",
...
}

和js代码本身:

var pouch = require('pouchdb');
var db = new pouch('mydb-websql');
console.log(db)

结果类似于以下内容:

> PouchDB$5 {   __opts: { name: 'mydb-websql', adapter: 'leveldb' },  
> auto_compaction: undefined,   prefix: '_pouch_',   name:
> 'mydb-websql',   _adapter: 'leveldb',   domain: null,   _events: {},  
> _eventsCount: 0,   _maxListeners: undefined,   taskqueue:    TaskQueue$1 {
>      isReady: false,
>      failed:
>       Error: Error: Could not locate the bindings file. Tried:
>        Ôćĺ c:\learning\electron\node_modules\pouchdb\node_modules\leveldown
> \build\leveldown.node
>        Ôćĺ c:\learning\electron\node_modules\pouchdb\node_modules\leveldown
> \build\Debug\leveldown.node
>        Ôćĺ c:\learning\electron\node_modules\pouchdb\node_modules\leveldown
> \build\Release\leveldown.node
>        Ôćĺ c:\learning\electron\node_modules\pouchdb\node_modules\leveldown
> \out\Debug\leveldown.node
>        Ôćĺ c:\learning\electron\node_modules\pouchdb\node_modules\leveldown
> \Debug\leveldown.node
>        Ôćĺ c:\learning\electron\node_modules\pouchdb\node_modules\leveldown
> \out\Release\leveldown.node
>        Ôćĺ c:\learning\electron\node_modules\pouchdb\node_modules\leveldown
> \Release\leveldown.node
>        Ôćĺ c:\learning\electron\node_modules\pouchdb\node_modules\leveldown
> \build\default\leveldown.node
>        Ôćĺ c:\learning\electron\node_modules\pouchdb\node_modules\leveldown
> \compiled\6.5.0\win32\x64\leveldown.node: unable to import leveldown
>           at requireLeveldown (c:\learning\electron\node_modules\pouchdb\li b\index.js:5173:12)
>           at PouchDB$5.LevelDownPouch (c:\learning\electron\node_modules\po uchdb\lib\index.js:5373:17)
>           at new PouchDB$5 (c:\learning\electron\node_modules\pouchdb\lib\i ndex.js:2753:36)
>           at Object.<anonymous> (c:\learning\electron\main.js:6:10)
>           at Module._compile (module.js:556:32)
>           at Object.Module._extensions..js (module.js:565:10)
>           at Module.load (module.js:473:32)
>           at tryModuleLoad (module.js:432:12)
>           at Function.Module._load (module.js:424:3)
>           at loadApplicationPackage (C:\Users\adam\AppData\Roaming\npm\node_modu
> les\electron\dist\resources\default_app.asar\main.js:280:12),
>      queue: [] },   adapter: 'leveldb' } 

当我使用websql适配器结果甚至我会说更糟:

App threw an error during load
Error: Invalid Adapter: websql
    at new PouchDB$5 (c:\learning\electron\node_modules\pouchdb\lib\index.j
s:2745:11)
    at Object.<anonymous> (c:\learning\electron\main.js:6:10)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at loadApplicationPackage (C:\Users\adam\AppData\Roaming\npm\node_modules\el
ectron\dist\resources\default_app.asar\main.js:280:12)
    at Object.<anonymous> (C:\Users\adam\AppData\Roaming\npm\node_modules\electr
on\dist\resources\default_app.asar\main.js:322:5)
    at Module._compile (module.js:556:32)

我必须承认,我试图重建一切,我尝试了所有适配器没有好结果。我试图另外安装sqlite3并再次失败。

你是否有任何其他想法可能会出现什么问题,或者我可能会发现我的错误?

我尝试在linux下使用和不使用适配器的相同代码。我认为它不依赖于os

1 个答案:

答案 0 :(得分:0)

好的,我发现了这个问题。问题与操作系统有关,这一切都是围绕重新编译sqlite3。实际上我需要添加Windows工具包并稍后设置路径到python(我从错误中读取它)。我确定在linux下检查一切顺利。

将我的操作系统更改为Linux可能会更安全,但实际上我需要为Windows开发。我需要找到平衡的方式;)