Reputation: 1514
I'm using nextjs: 13.1.6 oracledb: 5.5.0
I'm getting the following error:
Server Error
Error: NJS-045: cannot load a node-oracledb binary for Node.js 18.14.0 (win32 x64)
Looked for
C:\path\to\my\project\MyProjectName\.next\server\app\accounts\build\Release\oracledb-5.5.0-win32-x64.node,
C:\path\to\my\project\MyProjectName\.next\server\app\accounts\build\Release\oracledb.node,
C:\path\to\my\project\MyProjectName\.next\server\app\accounts\build\Debug\oracledb.node,
C:\path\to\my\project\MyProjectName\.next\server\app\accounts\editUsernamePassword\node_modules\oracledb\build\Release\oracledb-5.5.0-win32-x64.node,
C:\path\to\my\project\MyProjectName\.next\server\app\accounts\editUsernamePassword\node_modules\oracledb\build\Release\oracledb.node
Node-oracledb installation instructions: https://oracle.github.io/node-oracledb/INSTALL.html
My code looks like this: \src\app\accounts\editUsernamePassword\page.js
\\first line of code
import {oracleDB} from '@/library/database/oracle';
\src\library\database\oracle.js
const oracledb = require('oracledb');
//this is how to point to the Oracle Client without editing the PATH variable.
try {
oracledb.initOracleClient({libDir: "C:\\pathToMyInstantClient\\oracle\\instantclient_21_9"});
} catch (err) {
console.error('Unable to locate Oracle Instant Client.');
console.error(err);
process.exit(1);
}
/// ... then, go on to use the oracledb object
First question. From the error message, it looks like it's not able to find the oracledb*.node file. Is that correct? At first, I assumed it wasn't finding the Oracle Instant Client, but that doesn't seem to be the case. Instead, the problem is that it can't find the oracledb*.node file.
Second, if my assumption (in 1) is true, why is it looking for the oracledb*.node relative to the app/accounts page? I suppose I could copy the file there, but then I'd need to copy the client to every path that needs it.
Shouldn't it be looking for it here:? I've confirmed the oracledb*.node files are here:
C:\path\to\my\project\MyProjectName\node_modules\oracledb\build\Release
What's further confusing to me is that this import doesn't always fail. I have another file: \src\library\oasis\abcHelper.js
\\first line of code
import {oracleDB} from '@/library/database/oracle';
//then, it goes on to successfully use the oracle library
I have no idea why abcHelper.js is able to load the library, but page.js is looks for the library in the wrong place?
I did see this comment inside of oracledb.js, where it seems like they're discussing the issue, but I am not sure how to implement the solution:
// For Webpack. A Webpack copy plugin is still needed to copy 'node_modules/oracledb/build/' to the output directory
// See https://github.com/oracle/node-oracledb/issues/1156
When I do npm run dev, I get this warning, but I'm not sure if that is the root cause.
wait - compiling /accounts/editUsernamePassword/page (client and server)...
warn - ./node_modules/oracledb/lib/oracledb.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
Import trace for requested module:
./node_modules/oracledb/lib/oracledb.js
./node_modules/oracledb/index.js
./src/library/database/oracle.js
./src/app/accounts/editUsernamePassword/page.js
My current next.config.js:
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
appDir: true,
},
}
module.exports = nextConfig
Upvotes: 0
Views: 3158
Reputation: 10721
Update: for Webpack and node-oracledb 6.0, see Bundling node-oracledb JavaScript apps with Webpack.
With Webpack and node-oracledb 5.5 you need a copy plugin in webpack.config.js to copy the node-oracledb binary:
plugins: [
new CopyPlugin([
{
// Copy the binary Oracle DB driver to dist.
from: path.resolve(__dirname, 'node_modules/oracledb/build/Release'),
to: 'oracledb',
},
]),
. . .
],
Tips are in https://github.com/oracle/node-oracledb/issues/1156#issuecomment-598017250
Upvotes: 0