Angular [错误:NJS-045] @nguniversal/express-engine SSR 无法为 Node.js 加载 node-oracledb 二进制文件

问题描述

我正在 Angular 上做一个简单的项目:^11 + @nguniversal/express-engine for SSR。在我的项目中,我尝试使用 OracleDB[Docker: store/oracle/database-enterprise:12.2.0.1] 在服务器端为动态 Web 应用程序创建 REST-API。

在使用 oracledb 打开池时出现如下错误:

D:\project\server\main.js:149903
      throw new Error(nodbUtil.getErrorMessage('NJS-045',nodeInfo));
      ^

Error: NJS-045: cannot load a node-oracledb binary for Node.js 12.18.3 (win32 x64)
  Looked for D:\project\dist\project\build\Release\oracledb-5.1.0-win32-x64.node,D:\project\dist\project\build\Release\oracledb.node,D:\project\dist\project\build\Debug\oracledb.node,D:\project\dist\project\server\node_modules\oracledb\build\Release\oracledb-5.1.0-win32-x64.node,D:project\dist\project\server\node_modules\oracledb\build\Release\oracledb.node.....

我在 TypeScript 中尝试过这个类,效果很好,但 angular 不行。

import * as oracledb from 'oracledb';
import Connections from '../config/connections';

class Database {

  public openConnections = async () => {

    const connection = new Connections().getInfo();
    
    try {

      oracledb.initOracleClient({
        libDir: 'D:\\lib\\instantclient_19_9',});

      await oracledb.createPool({
        user: connection.user,password: connection.password,connectionString: connection.connectString,poolAlias: connection.poolAlias,poolMin: connection.poolMin,poolMax: connection.poolMax,poolIncrement: connection.poolIncrement,});
      
    } catch (error) {
      console.warn(error);
    }
  }
}

我在服务器创建之前调用 server.ts 中的 Database 类...

...
...
   endpoints(application);
   await new Database().openConnections();
   server.listen(port,() => {
    console.log(`Node Express server listening on http://localhost:${port}`);
   });
}
...
...

这个数据库类有问题还是...?

参考:

Angular CLI: 11.0.5
Node: 12.18.3
Angular: 11.0.5

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)