SAP / node-rfc

Asynchronous, non-blocking SAP NW RFC SDK bindings for Node.js
Apache License 2.0
249 stars 73 forks source link

node-rfc not running when using Node.js in "standalone mode" #238

Closed Zefau closed 2 years ago

Zefau commented 2 years ago

Describe the bug

Connecting via node-rfc with an installed version of Node.js works perfectly fine (via command-line node script.js).

Using the standalone exe file from Node.js (meanig node.exe from the binaries available at https://nodejs.org/en/download/) the error Error: A dynamic link library (DLL) initialization routine failed. is thrown.

To Reproduce

Running the following script (saved in script.js) via node script.js on the command line works perfectly. The result outputs the result of the remote function.

console.log(`Node.js Version: ${process.version}`);

process.env.PATH = process.env.PATH + ';' + process.cwd() + '\\lib\\binding;' + process.cwd() + '\\lib\\nwrfcsdk\\lib;' + process.cwd() + '\\lib\\nwrfcsdk;';
process.env.SAPNWRFC_HOME = process.cwd() + '\\lib\\nwrfcsdk';

/*
 */
const noderfc = require('node-rfc');
console.log(noderfc.noderfc_binding);
console.log(noderfc.environment);

const logon = {
    ... valid logon details ...
}

const pool = new noderfc.Pool({ 'connectionParameters': logon });

(async () => {
    try {
        const client = await pool.acquire();
        const result = await client.call("RFC_SYSTEM_INFO", {});
        console.log(result);
    }
    catch (error) {
        console.error(error);
    }
})();

Running the same script via downloaded exe-file using node.exe script.js (when being the same folder) results in the error mentioned above.

The path(s) to the nwrfcsdk is valid in both cases (via PATH variable, which is set in the beginning of the script). Furthermore, the sapnwrfc.node is also found on the paths provided (in case it is not found a different error is thrown).

The same setup works e.g. for better-sqlite3 (https://www.npmjs.com/package/better-sqlite3), which also compiled to a .node file. Though, an additional path to a sdk is not required.

Screenshots

None.

Environment

Installed Node.js outputs:

Node.js Version: v14.18.0
{
  platform: { name: 'win32', arch: 'x64', release: '10.0.18363' },
  env: {
    SAPNWRFC_HOME: 'C:\\Users\\... valid path ...\\lib\\nwrfcsdk',
    RFC_INI: '',
    nwrfcsdk_lib_on_path: true
  },
  versions: {
    node: '14.18.0',
    v8: '8.4.371.23-node.84',
    uv: '1.42.0',
    zlib: '1.2.11',
    brotli: '1.0.9',
    ares: '1.17.2',
    modules: '83',
    nghttp2: '1.42.0',
    napi: '8',
    llhttp: '2.1.3',
    openssl: '1.1.1l',
    cldr: '39.0',
    icu: '69.1',
    tz: '2021a',
    unicode: '13.0'
  },
  noderfc: {
    version: '2.5.1',
    nwrfcsdk: { major: 7500, minor: 0, patchLevel: 8 }
  }
}

Standalone Node.js outputs:

Node.js Version: v14.18.0
C:\Users\ ... \node_modules\node-rfc\lib\wrapper\noderfc-bindings.js:45
    throw ex;
    ^

Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\Users\ ... \node_modules\node-rfc\lib\binding\sapnwrfc.node

The SAP NW RFC SDK could not be loaded, check the installation: https://github.com/SAP/node-rfc/blob/master/doc/installation.md#sap-nwrfc-sdk-installation
environment: {
  "platform": {
    "name": "win32",
    "arch": "x64",
    "release": "10.0.18363"
  },
  "env": {
    "SAPNWRFC_HOME": "C:\\Users\\... same path as above ...\\lib\\nwrfcsdk",
    "RFC_INI": "",
    "nwrfcsdk_lib_on_path": true
  },
  "versions": {
    "node": "14.18.0",
    "v8": "8.4.371.23-node.84",
    "uv": "1.42.0",
    "zlib": "1.2.11",
    "brotli": "1.0.9",
    "ares": "1.17.2",
    "modules": "83",
    "nghttp2": "1.42.0",
    "napi": "8",
    "llhttp": "2.1.3",
    "openssl": "1.1.1l",
    "cldr": "39.0",
    "icu": "69.1",
    "tz": "2021a",
    "unicode": "13.0"
  }
}

Additional context

I think solving this might also be solving https://github.com/SAP/node-rfc/issues/144.

bsrdjan commented 2 years ago

Could you please describe steps how to install/run NodeJS in "standalone mode" on Windows?

Zefau commented 2 years ago
  1. Downloading node.exe from https://nodejs.org/dist/v14.18.1/win-x64/ (in my case x64)
  2. Copying node.exe and the script above in the same folder (alternatively renaming node.exe to cli.exe or anything)
  3. Opening command prompt in that folder
  4. Running node.exe script.js (or cli.exe script.js) [ Note that .exe is important; otherwise the global installed Node.js will be used ]
bsrdjan commented 2 years ago

The nodejs installation from binary archive is described only for Linux and it should work the similar way on Windows:

https://github.com/nodejs/help/wiki/Installation

The complete Windows binary archive should be downloaded and that bin folder must be first (or prioritized) on PATH, like described in above mentioned documentation.

Could you please try if it works with the recommended installation?

Zefau commented 2 years ago

Unbelievable - thank you very much for your help.

There is no bin folder in the windows binaries and it works only with the node.exe. But apparently it is slightly different in the binaries than the one I downloaded before?! The one in the binary works now as expected. And renaming the exe-file like I wrote above does not work - needs to be named node.exe.

bsrdjan commented 2 years ago

That is interesting, perhaps this is indeed the issue happening in #144?

Zefau commented 2 years ago

Seems like it, but I don't know how to solve this with respect to Electron. I was also trying to get node-rfc running with Electron, but I failed, which is why I ended up using this "standone mode" of Node.js as a fallback.

I was also trying pkg (https://www.npmjs.com/package/pkg), which apparentely uses an own compiled version of Node.js in some way. With pkg it also fails - same as Electron.