我正在使用新的 Node.js Tools for Visual Studio 并包含 sqlite3 npm 模块。当我调用
require('sqlite3')
时,它会抛出错误:
Error: Cannot find module './binding\Debug\node-v11-win32-ia32\node_sqlite3.node'
奇怪的是,当我忽略错误并继续运行代码时,一切正常......直到我所在的函数返回;然后服务器崩溃了。
还有其他人遇到过这个问题吗?我怀疑它与
./binding
部分有关,但不知道从哪里开始找出原因。
使用这个:-
npm install sqlite3 --build-from-source
这对我有用:https://www.npmjs.com/package/sqlite3
npm install https://github.com/mapbox/node-sqlite3/tarball/master
来自:https://github.com/mapbox/node-sqlite3/wiki/Building-On-Windows
npm install sqlite
npm install
node-gyp configure build
我遇到了这样的问题,我的
node
版本是v10.16.3
这个全局安装的 sqlite3 在加载时出现错误 require('sqlite3')
通过在项目本地安装 sqlite3 解决了这个问题。
$ npm install sqlite3
注意没有 -g 选项,它对我有用。
这似乎是
sqlite3
npm 包本身的问题。存在 lib\binding\Release\
文件夹,但不存在 lib\binding\Debug\
文件夹。我刚刚创建了 Release
文件夹的副本,将其命名为 Debug
,一切都很好。
如果上述方法对任何人都不起作用,那么这对我有用:
sudo apt install node-sqlite3
(我使用 Ubuntu 和 Vscode 作为编辑器)。看来安装这个node-sqlite3模块是被识别的。
对我来说,根本原因是 Dockerfile 在需要
npm
来实现跨操作系统兼容性时指定了 yarn
。
要跳过搜索预编译的二进制文件并强制从源代码构建,请使用
npm install --build-from-source