-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webpack: Error: NJS-045: cannot load a node-oracledb binary for Node.js 10.16.3 (win32 x64) #1156
Comments
Previous issues mentioning webpack found that changing the require() line in lib/oracledb.js helped. Hardcode the path and see if that helps: https://github.com/oracle/node-oracledb/blob/v4.0.1/lib/oracledb.js#L67 Or consider using pkg, see #1098 (comment) |
Thanks for your answer. |
@yakov-rs what was the exact solution for you? |
@yakov-rs I came across my notes from a Slack discussion last year about (presumably) node-oracledb 3.0. Apologies to the uncredited author, but she/he said:
|
@cjbj
Both solution required to change "oracledb.js" file. |
@yakov-rs thanks for sharing! |
That is how I solved the problem (still hacky though):
|
If there is a solution that doesn't involve copying, and is not dependent on other modules (eg not #851), we'd easily be able to add new paths to the search list https://github.com/oracle/node-oracledb/blob/v4.1.0/lib/oracledb.js#L59-L63 |
A quick solution would be to add For a solution to work with webpack out of the box you would have to hardcode all possible |
@MisterMX we can do that. Can you post the exact copy plugin code that users would then need to use (I assume it is a cutdown version of what you posted)? |
Actually, that's all it. The copy plugin copies the binaries into Here is a full
|
@MisterMX thanks for that. The change planned for
|
@MisterMX the load path change landed in node-oracledb 4.2, see https://github.com/oracle/node-oracledb/blob/v4.2.0/lib/oracledb.js#L59-L66 Let us know if this is optimal. |
Sorry for the late response. Unfortunately, your solution does not work because it still uses I added a simple function
Just tested it with my code and it worked. Hope this helps. Best |
I can add that. Doesn't the second |
@MisterMX also please check whether this works in Webpack:
Or perhaps this is better:
because your method fails in vanilla Node.js. With this change, does |
@cjbj your code also works with Webpack 👍 The extra By "second require" you mean
? You don't need to change that, because What does cause a problem is the This behaviour can be changed in the I am not exactly sure what would be the best way to fix this, as Since it is not really an issue, I would also agree to just ignore it, since Webpack developers should be aware of the |
@MisterMX thanks for the info. With the planned change to use The current diff I'm proposing is: diff --git a/lib/oracledb.js b/lib/oracledb.js
index 23a96788..998d248d 100644
--- a/lib/oracledb.js
+++ b/lib/oracledb.js
@@ -56,6 +56,8 @@ const defaultPoolAlias = 'default';
// Load the Oracledb binary
+const requireBinary = (typeof __non_webpack_require__ === 'function') ? __non_webpack_require__ : require; // See Issue 1156
+
const binaryLocations = [
'../' + nodbUtil.RELEASE_DIR + '/' + nodbUtil.BINARY_FILE, // pre-built binary
'../' + nodbUtil.RELEASE_DIR + '/' + 'oracledb.node', // binary built from source
@@ -68,13 +70,14 @@ const binaryLocations = [
let oracledbCLib;
for (let i = 0; i < binaryLocations.length; i++) {
try {
- oracledbCLib = require(binaryLocations[i]);
+ oracledbCLib = requireBinary(binaryLocations[i]);
break;
} catch(err) {
if (err.code !== 'MODULE_NOT_FOUND' || i == binaryLocations.length - 1) {
let nodeInfo;
if (err.code === 'MODULE_NOT_FOUND') {
- // a binary was not found in any of the search directories
+ // A binary was not found in any of the search directories.
+ // Note this message may not be accurate for Webpack users since Webpack changes __dirname
nodeInfo = `\n Looked for ${binaryLocations.map(x => require('path').resolve(__dirname, x)).join(', ')}\n ${nodbUtil.getInstallURL()}\n`;
} else {
nodeInfo = `\n Node.js require('oracledb') error was:\n ${err.message}\n ${nodbUtil.getInstallHelp()}\n`; |
@MisterMX I would love to see a basic, runnable example on using Webpack with node-oracledb. The hack Webpack example I threw together works the same with and without the above change. |
@MisterMX is the change above OK? |
I created a simple Webpack example: https://github.com/MisterMX/node-oracledb-webpack-example The project does not run with If I add your changes from above, it works. |
@MisterMX thank you. I'll merge the patch to the master branch when I get a chance. |
@MisterMX would it be cleaner if we changed the paths in
This would give a flatter
Your
What do you think? |
@MisterMX ping |
Sorry, @cjbj, I was caught up with other projects. Sure, you could do that. I am not really sure, if there is a correct way to do this. In our project, we copy the files to If you think your way is cleaner, we can go this way. I don't think it would make much of a difference. |
@MisterMX that's a good argument. My thoughts were that currently on Windows you can copy the Instant Client DLLs to the same directory where oracledb-4.2.0-win32-x64.node is and have a complete, self-standing application that can be distributed without users needing to set PATH. (I'm still hopeful Oracle can change its build steps when creating libclntsh on Linux to also make this work on Linux in a future). Since Instant Client is not part of node-oracledb, it seems odd to put Instant Client in a node_modules subdirectory. Let me discuss it with the team and then make a decision. |
@MisterMX no one else had a strong opinion so I went with For future readers, your
|
Looks, good. Thanks for implementing it 👍 |
I just went through this using Windows 10 x64, Oracle Instant Client 19.6, node v10.21.0, and oracle/node-oracledb.git#v4.2.0. It still required both CopyPlugin and string-replace-loader to get it to work. Thanks for the solution. |
@dbertozzi thanks for the feedback. We just released node-oracledb 5.0; you could try with it. I'm expecting you'll just need the CopyPlugin. |
With node-oracledb 6.0 you don't need the copy plugin by default. This makes using node-oracledb with Webpack trivial - and apps become immediately portable. Check out my blog post Bundling node-oracledb JavaScript apps with Webpack. |
Help me please resolve a problem with description below:
I developed server (express + oracledb) witch work perfect and have no problem with getting data from Oracle.
Then I wanted to create a bundle (using webpack 4) and run my bundle separeted from directory where I working.
And I've got the next message (my problem):
I placed my bundle into "D:\test" catalog.
I copied oracledb-4.0.1-win32-x64.node file into "D:\test\build\Release" catalog (but error is still have).
My webpack config is really simple:
node --version
v10.16.3
Oracle Client version 12.2.0.1.0
Thanks for any future help or advice.
The text was updated successfully, but these errors were encountered: