oracle / node-oracledb

Oracle Database driver for Node.js maintained by Oracle Corp.
http://oracle.github.io/node-oracledb/
Other
2.26k stars 1.07k forks source link

Using v5.3 with typescript > 4.3.x brings error "Cannot read properties of undefined (reading '_initOracleClient')" #1462

Closed maku closed 2 years ago

maku commented 2 years ago
  1. What versions are you using?

Give your database version: Oracle Database 18c Standard Edition 2 Release 18.0.0.0.0 - Production

Also run Node.js and show the output of:

process.platform win32
process.version: v16.13.0
process.arch: x64

node dependency "oracledb": "5.3.0"
  1. Is it an error or a hang or a crash?

    error

  2. What error(s) or behavior you are seeing?

oracledb.js -> function initOracleClient -> Line 144 this is undefined

Uncaught TypeError: Cannot read properties of undefined (reading '_initOracleClient')

The same functionality works with typescript <= 4.3.x, with typescript >= 4.4 I get the error

example typescript code:

import { ConnectionAttributes, initOracleClient, Connection, getConnection } from 'oracledb';
...
initOracleClient({ libDir: process.env[ORACLE_CLIENT_LIBDIR] });
cjbj commented 2 years ago
maku commented 2 years ago

@cjbj I do not understand. When I remove the import of "initOracleClient" I am not able to compile the typescript code....

cjbj commented 2 years ago

You could help us by:

cjbj commented 2 years ago

@maku never mind; I just spent some Saturday time and reproduced it. @anthony-tuininga supplied a patch that resolves it for us.

--- a/lib/oracledb.js
+++ b/lib/oracledb.js
@@ -105,6 +105,7 @@ class OracleDb {
     this.createPool = nodbUtil.callbackify(createPool).bind(_oracledb);
     this.shutdown = nodbUtil.callbackify(shutdown).bind(_oracledb);
     this.startup = nodbUtil.callbackify(startup).bind(_oracledb);
+    this.initOracleClient = this.initOracleClient.bind(_oracledb);
   }

   // temporary method for determining if an object is a date until

Try putting that in a .patch file installed via a postInstall script in your package.json, see https://github.com/oracle/node-oracledb/issues/1391#issuecomment-884568248.

Thanks for reporting the issue.

cjbj commented 2 years ago

Closing the issue. The fix was in the node-oracledb 5.4 release from back in June. Thanks for reporting it.