I have built a node app that uses a module to work with a database (better-sqlite3).
It works fine as a node app. but, Now I am trying to make a VS Code extension that has most of the same functionality.
However, when I install the module, build, and run the new extension I get this message:
Activating extension 'undefined_publisher.myPlugin' failed: The module '\?\C:...\node_modules\better-sqlite3\build\Release\better_sqlite3.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 72. This version of Node.js requires NODE_MODULE_VERSION 75. Please try re-compiling or re-installing the module (for instance, using
npm rebuild
ornpm install
)..
I understand that VS Code extensions are Electron apps and they use a different version of the node then the one I created for my pure node app but I am unclear what I have to do in the extension to build the module (better-sqlite3) with the correct version of node?
npm rebuild
compiles the code under plain node. It will not build addons.
To resolve, you have to do the following:
npm install --save-dev electron-rebuild
# Every time you run "npm install", run this:
./node_modules/.bin/electron-rebuild
# On Windows if you have trouble, try:
.\node_modules\.bin\electron-rebuild.cmd
Also, if the above doesn't work, you have some cleaning and rebuilding to do, which is as follows:
npm i -D electron-rebuild
node-modules
folder the <your-module-name>
and @<your-module-name>
folders.packages-lock.json
npm i
to install non-installed modules./node_modules/.bin/electron-rebuild
or corresponding windows equivalent - .\node_modules\.bin\electron-rebuild.cmd
It is very important to run the above command directly after npm i.Reference: Electron docs - https://www.electronjs.org/docs/tutorial/using-native-node-modules
Similar issue - https://github.com/mscdex/cap/issues/92
Similar issue - https://github.com/serialport/node-serialport/issues/1910
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With