NJS-045: cannot load the oracledb add-on binary
i'm using Jest to test my server
on OSX node version : v6.9.1 oracledb version : 1.12.0 gcc version : 4.2.1
error message is :
NJS-045: cannot load the oracledb add-on binary
at Object.<anonymous> (node_modules/oracledb/lib/oracledb.js:51:15)
I found oracledb.js line 35
oracledbCLib = require('../build/Release/oracledb');
But there is only node_module/oracledb/build/Release/oracledb.node in it
change oracledb.js line 35 to
oracledbCLib = require('../build/Release/oracledb.node');
it works
But I want to know is osx build problem or what?
I don't what to change the code after I build it every time
Does a non-Jest test script work? What did you run to install node-oracledb?
Hi, I have the same issue trying to use oracledb library with Node-Red. 16 Jan 15:12:58 - [warn] [oracledb] Error: NJS-045: cannot load the oracledb add-on binary My env is a Mac too. By the way, I believe I followed all the steps in the install instructions.
I have also tried to use something different from node-red, and apparently it works. I got a diff error message related to a non existing database.
So, I am struggling to go over NJS-045 error. Any idea please ?
@giulianodm does a non-node red app (e.g example work? What if you set NODE_PATH to the node_modules directory?
Hi @cjbj . Yes it does work. See the trace below.
--> node select1.js log -- /Users/giulianodm/node_modules/oracledb/lib ORA-12154: TNS:could not resolve the connect identifier specified
PS.: The TNS error is because I don't have a proper OracleDB that I can use at the moment.
Can you do add some console.logs and check what the working directory etc are in both cases?
What if you set NODE_PATH?
Hi @cjbj Actually NODE_PATH was not set. I just did it, and gave another try. Same NJS-045 error.
echo $NODE_PATH /Users/giulianodm/node_modules
ls -la /Users/giulianodm/node_modules/ drwxr-xr-x 12 giulianodm staff 408 Jan 16 12:30 oracledb
ls -la /Users/giulianodm/node_modules/oracledb/ total 168 drwxr-xr-x 12 giulianodm staff 408 Jan 16 12:30 . drwxr-xr-x 4 giulianodm staff 136 Jan 16 12:30 .. -rw-r--r-- 1 giulianodm staff 18624 Dec 21 07:33 CHANGELOG.md -rw-r--r-- 1 giulianodm staff 36585 Mar 24 2016 LICENSE.md -rw-r--r-- 1 giulianodm staff 6110 Dec 12 23:33 README.md -rw-r--r-- 1 giulianodm staff 11162 Aug 19 00:14 binding.gyp drwxr-xr-x 8 giulianodm staff 272 Jan 16 12:30 build -rw-r--r-- 1 giulianodm staff 47 Feb 28 2016 index.js drwxr-xr-x 9 giulianodm staff 306 Jan 16 12:30 lib drwxr-xr-x 3 giulianodm staff 102 Jan 16 12:30 node_modules -rw-r--r-- 1 root staff 2033 Jan 16 12:30 package.json drwxr-xr-x 4 giulianodm staff 136 Jan 16 12:30 src
Regarding the logs... For the example code (node) that works:
node select1.js 0-/Users/giulianodm/node_modules/oracledb/lib 1-/Users/giulianodm/node_modules/oracledb/lib ORA-12154: TNS:could not resolve the connect identifier specified
For the node-red: node-red 0-/Users/giulianodm/node_modules/oracledb/lib 1-/Users/giulianodm/node_modules/oracledb/lib 17 Jan 11:15:52 - [info]
Welcome to Node-RED
17 Jan 11:15:52 - [info] Node-RED version: v0.16.0 17 Jan 11:15:52 - [info] Node.js version: v4.7.2 17 Jan 11:15:52 - [info] Darwin 16.3.0 x64 LE 17 Jan 11:15:53 - [info] Loading palette nodes 17 Jan 11:15:54 - [info] UI started at /ui 17 Jan 11:15:54 - [warn] ------------------------------------------------------ 17 Jan 11:15:54 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node 17 Jan 11:15:54 - [warn] [oracledb] Error: NJS-045: cannot load the oracledb add-on binary 17 Jan 11:15:54 - [warn] ------------------------------------------------------ 17 Jan 11:15:54 - [info] Settings file : /Users/giulianodm/.node-red/settings.js 17 Jan 11:15:54 - [info] User directory : /Users/giulianodm/.node-red 17 Jan 11:15:54 - [info] Flows file : /Users/giulianodm/.node-red/flows_Giulianos-MacBook-Pro-2.local.json 17 Jan 11:15:54 - [info] Creating new flow file 17 Jan 11:15:54 - [debug] loaded flow revision: 513fd923d68021b8ee98fcb250470340 17 Jan 11:15:54 - [debug] red/runtime/nodes/credentials.load : no user key present 17 Jan 11:15:54 - [debug] red/runtime/nodes/credentials.load : using default key 17 Jan 11:15:54 - [info] Starting flows 17 Jan 11:15:54 - [info] Started flows 17 Jan 11:15:54 - [info] Server now running at http://127.0.0.1:1880/
FYI - This is the code I've added the log - oracledb.js
`console.log("0-" +__dirname);
try { oracledbCLib = require('../build/Release/oracledb'); console.log("1-" + __dirname); } catch (err) { if (err.code !== 'MODULE_NOT_FOUND') { console.log("2-" +__dirname); throw err; } else { try { console.log("3-" + __dirname); oracledbCLib = require('../build/Debug/oracledb'); console.log("4-" +__dirname); } catch (err) { console.log("5-" +__dirname); if (err.code !== 'MODULE_NOT_FOUND') { throw err; } else { console.log("6-" +__dirname); throw new Error(nodbUtil.getErrorMessage('NJS-045')); } } } }`
This slipped past the keeper, did you get any further with it?
I fix it by change oracledb.js line 35
@yushanhsieh what did you change on line 35
@waleedahmed3045
I changed oracledb.js line 35 to
oracledbCLib = require('../build/Release/oracledb.node');
original line is
oracledbCLib = require('../build/Release/oracledb');
@yushanhsieh @waleedahmed3045 is this use of oracledbCLib = require('../build/Release/oracledb.node'); confirmed? Any thoughts about what is going on? Do you have multiple installs/builds? Where are you getting Node from? I'm asking so we can assess whether to patch node-oracledb
I resolved this error by running npm rebuild oracledb...
Steps to replicate issue:
-
Follow default oracledb, jest, and ts-jest setup instructions.
-
Implement simple.test.ts:
import * as oracledb from "oracledb";
test("oracle imports", () => {
expect(oracledb).toBeDefined();
});
- jest results:
FAIL src/simple.test.ts
● Test suite failed to run
NJS-045: cannot load the oracledb add-on binary
at Object.<anonymous> (node_modules/oracledb/lib/oracledb.js:46:15)
at Object.<anonymous> (node_modules/oracledb/index.js:1:45)
at Object.<anonymous> (src/simple.test.ts:1:1)
at next (native)
at next (native)
at process._tickCallback (internal/process/next_tick.js:109:7)
Notes:
- Attempted with NODE_PATH configured to <my_project_path>/node_modules as well as null.
- I encountered the same error utilizing Webpack on another project. The workaround used was to configure oracledb as an external library.
- The suggestion to run
npm rebuild oracledbdoes not resolve this issue. - Making the suggested change
oracledbCLib = require('../build/Release/oracledb.node');from above does work:PASS src/simple.test.ts - The latter change did not break my application.
@derrickbabb thanks for posting your solution. It would be nice to know why standard Node name resolution isn't working. The node-oracledb v2 driver gives some more heuristics which may help narrow this down in future.
Hi all,
I've lost a couple of days to solve this issue in my Windows environment, so I am posting this to help anyone that may end up having the same problem.
TL;DR
Even if you already have some Visual C++ Build Tools installed (e.g. 2015 in my case), make sure to install too the appropiate VS Redistributable for your oracle version.
In my case (Oracle Instant Client 12.2), I had to install the Build Tools 2013.
After doing so, I do not need to modify the '../build/Release/oracledb.node' path
Understanding the issue
I was able to reproduce the issue folowing @derrickbabb steps. However, setting the oracledbCLib path to '../build/Release/oracledb' (currently at line 33) would not resolve the issue for me.
I am running the test in a 64-bits Windows 10, and this is the stack trace I was getting:
Based on the error message, here are some more details of my environment:
- I downloaded the Oracle Instant Client (12.2.0.1.0, basic package + sdk package) from http://www.oracle.com/technetwork/topics/winx64soft-089540.html and unzipped it at C:\xxx\oracle\instant_client
- I had the Visual C++ Build Tools 2015 installed with the windows-build-tools npm package
npm install --global --production windows-build-tools - I modified the PATH environment variable to containt 'C:\xxx\oracle\instant_client'
- I added the OCI_VERSION, OCI_LIB_DIR and OCI_INC_DIR environment variables
Everything seemed to be fine, but since I was missing the appropriate VS Redistributable version, the oracle.node binary was not being successfully loaded.
I finally saw that in the installation instructions, but it took me ages because the error message is not very precise about it.
I don't pretend to justify my lack of attention to the install instructions, but may be the error handling could be a bit more concrete.
Thanks
@basalter I appreciate the post, and can hear your frustration.
If you have specific wording or layout suggestions, send them through. The instructions keep getting tuned and the bootstrap error messages can always be changed.
I can also edit the Instant Client download page directly, if you don't think they spell out which redistributable to install.
@cjbj The instant client download page is fine :)
About the error messages, I guess it is not that easy to improve the wording. In my case, what had been useful would be that the exception raised when requiring the library
oracledbCLib = require(binaryReleasePath);
mentioned the fact that the VS Redistributable is not installed (stating the version required) rather than just saying 'DPI-1047: 64-bit Oracle Client library cannot be loaded'. I imagine that this exception has nothing to do with the node package though
@basalter Improvements would require some heuristics to interrogate what is installed, and what versions. I'm not a Windows user. Can you submit a PR or some code snippets?
[For future readers, note that for node-oracledb 2 installation on Windows there are pre-built binaries available for current Node versions so you don't need a compiler and don't need to set to OCI_VERSION, OCI_LIB_DIR or OCI_INC_DIR: see the instructions]
I got reserved the issue.
just uninstall visual studio greater than 2013 then install only vs2013 https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
On Unix machine, i got this issue fixed by creating symbolic link for oracle client in /usr/local/lib
ln -s /opt/oracle/instantclient/libclntsh.dylib libclntsh.dylib