首页 > 解决方案 > 错误:NJS-045:无法为 Node.js 加载 oracledb 附加二进制文件

问题描述

在我的Node.JS项目中,我使用连接到远程ORACLE数据库的“ node-oracledb ”包。我在 Windows 10 操作系统中开发了该项目,它运行良好。现在在生产服务器(CentOS)中,我通过下一个 Dockerfile 创建了 Docker Image:

FROM node:latest
COPY / ./
EXPOSE 3001
CMD ["npm", "start"]

它创建 Docker Image 没有任何错误。然后我创建了 Docker 容器,但不幸的是在日志中我注意到了这个错误:

/src/node_modules/oracledb/lib/oracledb.js:68
      throw new Error(nodbUtil.getErrorMessage('NJS-045', nodeInfo));
      ^

Error: NJS-045: cannot load the oracledb add-on binary for Node.js 8.12.0 (linux, x64)
Cannot load /src/node_modules/oracledb/build/Release/oracledb.node
/src/node_modules/oracledb/build/Release/oracledb.node: invalid ELF header
Node-oracledb installation instructions: https://oracle.github.io/node-oracledb/INSTALL.html
You must have 64-bit Oracle client libraries in LD_LIBRARY_PATH, or configured with ldconfig.
If you do not have Oracle Database on this computer, then install the Instant Client Basic or Basic Light package from
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

    at Object.<anonymous> (/src/node_modules/oracledb/lib/oracledb.js:68:13)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/src/node_modules/oracledb/index.js:1:80)
    at Module._compile (module.js:653:30)

如何解决这个问题?

我使用 [官方文档][2] 中的说明安装客户端并设置环境变量。错误是窃取相同的。另外我认为我可以尝试在 docker 中安装 oracle 客户端,但我不知道如何制作。你怎么看?


我更改了 Dockerfile。我添加这个命令:

RUM npm rebuild oracledb

它引发了新的关闭错误:

/node_modules/oracledb/lib/oracledb.js:65
      throw new Error(nodbUtil.getErrorMessage('NJS-045', nodeInfo));
      ^

Error: NJS-045: cannot load the oracledb add-on binary for Node.js 11.4.0 (linux, x64)
Node.js require() error was:
  DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help
Node.js require() mapped to /node_modules/oracledb/build/Release/oracledb.node
Node-oracledb installation instructions: https://oracle.github.io/node-oracledb/INSTALL.html
You must have 64-bit Oracle client libraries in LD_LIBRARY_PATH, or configured with ldconfig.
If you do not have Oracle Database on this computer, then install the Instant Client Basic or Basic Light package from
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

    at Object.<anonymous> (/node_modules/oracledb/lib/oracledb.js:65:13)
    at Module._compile (internal/modules/cjs/loader.js:723:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Module.require (internal/modules/cjs/loader.js:659:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/node_modules/oracledb/index.js:1:80)
    at Module._compile (internal/modules/cjs/loader.js:723:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! saturn-backend@0.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the saturn-backend@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-12-28T12_06_50_714Z-debug.log

在此处输入图像描述

  [1]: https://github.com/oracle/node-oracledb
  [2]: https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

标签: node.jsoracledockernode-oracledb

解决方案


推荐阅读