Closed markddrake closed 1 year ago
@markddrake Electron uses its own node.js embedded with electron having own NODE_MODULE_VERSION which is always different from NODE_MODULE_VERSION of system wide Node.js. You can check NODE_MODULE_VERSION for Electron and Node.js here: https://github.com/nodejs/node/blob/master/doc/abi_version_registry.json For electron v20.x, NODE_MODULE_VERSION is 107 and for Node.js V18.x, NODE_MODULE_VERSION is 108. So, basically you have two Node.js environments. One that comes with electron and other the system wide node.js (v18.x). You can not compile a node-add on for electron and use with system Node.js and vice-versa. It is how electron works. So, the behavior observed by you is correct. If ibm_db is installed for electron, you can use it only with electron applications like VSCode. You can not use it with normal Node.js applications. If ibm_db is installed for node.js application, you can not use it for electron application. You need to find a way to use the embedded node.js of electron as library and use it. Probably info on this page help you: https://www.electronjs.org/blog/electron-internals-using-node-as-a-library The behavior observed by you is explained on this page in detail: http://blog.cinan.sk/2018/02/22/integrate-native-node-dot-js-modules-into-an-electron-app-1-slash-2/ Thanks.
I assume this is a side effect of ibm_db using ODBC under the covers, and all the other databases using a more 'node native' transport protocol?.
Is there anyway that you are aware of to have both versions of ibm_db installed in different location and configure node to look in one location and electron to look in another ?
Other wise I guess I need to pick up a node version that using NODE_MODULE_VERSION 107 for this to work.
I think I can do something like this
npm install ibm_db_electron@npm:ibm_db -electron=20.1.0
And then use a conditional import to load the electron version of the package when running under electron. Will need to experiment further
And then dynamically load ibm_db as follows
async testConnection() {
const ibmdb = await ( import(process.versions.hasOwnProperty('electron') ? "ibm_db_electron" : "ibm_db"))
const stack = new Error().stack
const connection = await new Promise((resolve,reject) => {
ibmdb.open(this.createConnectionString(),(err,conn) => {
if (err) reject(new DB2Error(this.DRIVER_ID,err,stack,'DB2.open()'))
resolve(conn)
})
})
return connection
}
Using the latest node and ibm_db@v3.0.0
Everything works as expected.
However I need to be able to use both node and electron from the same environment If I load the version of idb_db with the electron flag and repeat the same test I get
My electron version is
Is there a way to configure my environment so I can run node applications and electron applications?. I have a primarily command and server-based application, that can also be used using an electron-based user interface.