Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using better-sqlite3 in a VS Code extension #385

Closed
markm208 opened this issue Apr 28, 2020 · 6 comments
Closed

Using better-sqlite3 in a VS Code extension #385

markm208 opened this issue Apr 28, 2020 · 6 comments

Comments

@markm208
Copy link

I am wondering if anyone has experience using better-sqlite3 in a vs code extension? I created an extension using Yeoman as described in the docs.

I would like to take an existing node app that I have that uses better-sqlite3 (it works great in the standalone node app) and incorporate parts of it into the extension. When I install better-sqlite3 into the extension project and run I get this error:

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 or npm install).

I understand that vs code extensions use a special version of node. What I am unsure of is what I need to do in the extension project in order to use better-sqlite3? Code extensions are supposed to be able to be installed on different platforms, will this be possible?

@Prinzhorn
Copy link
Contributor

Prinzhorn commented Apr 28, 2020

I think this is unrelated to better-sqlite3. VS Code is based on Electron, which comes with its own version of Node. And since you cannot control which version of Electron / VS Code a given user has installed it's a hard problem to solve and it is not supported by VS Code, see microsoft/vscode#658

https://github.com/microsoft/vscode/search?q=NODE_MODULE_VERSION&type=Issues

@JoshuaWise
Copy link
Member

This is probably related to #271

@quanjinzhang
Copy link

you can try to use electron-rebuild -f -w better-sqlite3 to resolve this problem

@JoshuaWise
Copy link
Member

Closing due to inactivity

@zeluspudding
Copy link

zeluspudding commented Aug 4, 2023

Dormant but still very pertinent - I have the same issue and it appears our real problem is related to #545. Anyone wanting to use better-sqlite3 in a VS Code extension would have the same issue. Guessing I have to look through @vscode/test-electron for something similar to a ELECTRON_RUN_AS_NODE=true flag. In the mean time, has anyone around here by chance already solved this problem?

@zeluspudding
Copy link

zeluspudding commented Aug 4, 2023

Okay, after a total of 3 hours of troubleshooting, the solution goes like this - if you're seeing an error like

better_sqlite3.node was compiled against a different Node.js version using
NODE_MODULE_VERSION 99. This version of Node.js requires

NODE_MODULE_VERSION 110. Please try re-compiling or re-installing
the module

Then we need to update our local version of electron (as provided by the @vscode/test-electron module)

To update, run .\node_modules\.bin\electron-rebuild.cmd -v 6.1.2 where 6.1.2 should be the version you need. If you don't know which version you need, then check this compatibility table or just try different versions until you stop getting errors (where ensuing error messages will tell you if you're getting closer or further away from the right version).

UPDATE
Don't use native modules (which is what better-sqlite3 is) in your VS Code extensions if you intend to list it on the extension marketplace. Your end users will have a hell of a time trying to install / use them since a portion of them will inevitably have to rebuild the module's binary dependencies... which means they may need python or c++ installed.. It's a mess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants