TimelordUK / node-sqlserver-v8

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

Unable to initialize msnodesql during Hot Module Reload (HMR) #315

Open CarlosOnline opened 11 months ago

CarlosOnline commented 11 months ago

Looking for help on resolving Unable to initialize msnodesql error during HMR, using vite for electron.

Source: const msnodesqlv8 = require("mssql/msnodesqlv8");

Is there any reset or connection code I can apply to cause msnodesqlv8 to reload during HMR?

    void Connection::Init(Local<Object> exports) {
        Nan::HandleScope scope;
        const auto initialized = OdbcConnection::InitializeEnvironment();
        const auto name = Nan::New("Connection").ToLocalChecked();
        if (!initialized) {
            const nodeTypeFactory fact;
            MutateJS::set_property_value(exports, name, Nan::Null());
            fact.throwError("Unable to initialize msnodesql");
            return;
        }
TimelordUK commented 11 months ago

Im sorry I am not aware how this can be solved. Can you try storing require on global and fetch back cached version is it related to second call to initialise. Ideally can you inject the same instance in every time. I’m really not an expert of the front end side of things.

MikeNitsenko commented 11 months ago

@CarlosOnline did you find any solution for this? Please share of you have ideas =)

zlinker89 commented 1 month ago

I am having the same problem within a worker pool, when I try to dynamically import the library using require or import() it gives me this error, I have managed to make it work by adding a timeout of 300ms before importing mssql/msnodesqlv8, but this solution does not work all right