TimelordUK / node-sqlserver-v8

branched from node-sqlserver, SQL server driver compatible with all versions of Node
Other
139 stars 43 forks source link

Module did not self-register in Visual Studio Code #268

Open RomuAdq opened 1 year ago

RomuAdq commented 1 year ago

I try to tu use this driver in an Visual Studio code extension that I am working on.

I got the following error message : Module did not self-register.

I created a sample code :

const mssql = require('mssql')
require("mssql/msnodesqlv8");

mssql.connect({
    server: "XXXX",
    database: "XXXX",
    driver: "msnodesqlv8",
    options: {
        trustServerCertificate: true,
        trustedConnection: true,
    }
}).then(() => {
    console.log("Connected");
    return true
}).catch(res => {
    console.log("Erreur : " + res);
})

This code works by typing node sample.js but is not working on Visual Studio code...

TimelordUK commented 1 year ago

this is probably not easy to solve - see https://github.com/microsoft/vscode/issues/658

the msnodesqlv8 is using native cpp which means you need exact binary version matching the electron version being used by vscode.

you could try as below but Ihave not tried this myself - using native modules in vscode means every time an update or change occurs the native module would need to be rebuilt for that version.

@ganezdragon for what it's worth, I ask my users to go to the extension folder (~/.vscode/extensions/your-extensions-name-and-version on my Windows machine) after installation/updated, open a terminal there, and type npm install at the command prompt. This will fully rebuild the extension, including compiling the native parts. You have to redo this with every update, but so far it has worked for me every time. You just have to make sure the version of electron you reference tracks the Node.js ABI version, but if you can compile your extension locally, that is normally taken care of.