重新编译better-sqlite3以适配当前Node.js版本。具体步骤如下:
npm uninstall better-sqlite3
npm install node-gyp
安装Python 2.7版本和Visual C++ Build Tools。
重新编译并安装better-sqlite3模块,指定编译时使用的Node.js版本:
npm install better-sqlite3 --build-from-source --runtime=node --target=
例如,如果当前的Node.js版本为v14.16.1,则编译命令为:
npm install better-sqlite3 --build-from-source --runtime=node --target=14.16.1
编译完成后,在项目中引入新安装的better-sqlite3模块即可:
const Database = require('better-sqlite3');
这样就可以在不同版本的Node.js下正常使用better-sqlite3模块了。