5

排错:使用 Better Sqlite3 的项目报错 compiled against a different Node version

 2 years ago
source link: https://blog.dteam.top/posts/2022-09/better_sqlite3-was-compiled-against-a-different-node-version.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

排错:使用 Better Sqlite3 的项目报错 compiled against a different Node version

胡键 Posted at — Sep 17, 2022 阅读 9

使用 Better Sqlite3 的 node 项目运行报错,错误信息如下:

Error: The module '.../node_modules/better-sqlite3/build/Release/better_sqlite3.node'
  was compiled against a different Node.js version using
  NODE_MODULE_VERSION 83. This version of Node.js requires
  NODE_MODULE_VERSION 93. Please try re-compiling or re-installing
  the module (for instance, using `npm rebuild` or `npm install`).

  › the module (for instance, using `npm rebuild` or `npm install`).
  › bindings (node_modules/bindings/bindings.js:112:48)

错误信息本身已经包含了足够的信息,同时给出了原因和解决办法。简单来讲就是:对于当前所装的 better_sqlite3,编译用的 node 版本和当前使用的 node 版本不一致,建议重新用当前版本编译一次。

  1. npm i -D electron-rebuild

  2. 删除 node_modules 目录。

  3. package.jsonscripts 添加:

     "rebuild": "electron-rebuild -f -w better-sqlit3",
    
  4. npm i

  5. npm rebuild

参考链接:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK