我想在已编译的node.js app中使用一个简单的数据库。如果不单独安装数据库,这可能吗?即我希望数据库包含在.exe文件中,以便我可以复制并执行该文件。
我正在使用pkg
来创建.exe文件并且效果很好,但是当我尝试使用以下警告执行{。}} npm模块时出现.exe错误:
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)
这看起来类似于此处修复的sqlite3错误:sqlite3(因为错误已修复,我认为这是用户问题)
查看错误消息,看起来无法找到...../bide_sqlit3.node
文件。在我的开发环境中查看node_modules/
(模块工作的地方)我找不到该文件。所以我假设文件没有包含在可执行文件中,我需要做一些事情:
pkg
包含二进制文件如何使用zeit/pkg
执行此操作?或者,如果这更正确:如何强制npm将二进制文件安装到node_modules然后引用这些二进制文件?
答案 0 :(得分:3)
您应该将构建的node-sqlite3.node放在与使用pkg构建的二进制文件相同的目录中(如this issue中所述)。该文件可以在node_modules / sqlite3 / lib / binding / node-vxx-xxxxx-xxx / node_sqlite3.node中找到。
您还需要确保使用与您使用sqlite3构建的节点版本相同的pkg构建项目。