6

I want to make use of a simple database in a compiled node.js app. Is this possible without installing the database separately? i.e I want the database to be included in the .exe file so that I can just copy and execute that file.

I'm using pkg to create .exe files and it works well, but when I use the sqlite3 npm module the .exe errors when I try to execute with the following warning:

pkg/prelude/bootstrap.js:1155
      throw error;
      ^

Error: Cannot find module 'C:\snapshot\sqlite\node_modules\sqlite3\lib\binding\node-v51-win32-x64\node_sqlite3.node'
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1252:46)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at Module.require (pkg/prelude/bootstrap.js:1136:31)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\snapshot\sqlite\node_modules\sqlite3\lib\sqlite3.js:4:15)
    at Module._compile (pkg/prelude/bootstrap.js:1226:22)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)

Which looks similar to a sqlite3 bug that was fixed here: https://github.com/zeit/pkg/issues/183 (since the bug was fixed I assume this is a user issue)

Looking at the error message, it looks like the ...../bide_sqlit3.node file can't be found. And looking at node_modules/ in my development env (where the module works) I can't find that file. So I assume that the file is NOT being included in the executable and that I need to do something that:

  1. Makes pkg include the file in the binary
  2. Alters the path to the file to be the path to the file in the binary

How do I do this with zeit/pkg? or, if this is more correct: How do I force npm to to install binaries to node_modules and then reference those binaries?

4

1 回答 1

11

您应该将构建的 node-sqlite3.node 与您使用 pkg 构建的二进制文件放在同一目录中(如本期所述)。这个文件可以在你的 node_modules/sqlite3/lib/binding/node-vxx-xxxxx-xxx/node_sqlite3.node 中找到。

您还需要确保使用 pkg 使用与构建 sqlite3 相同的节点版本构建项目。

于 2017-10-24T17:08:36.583 回答