SAP / node-rfc

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

Question: Offline installation #200

Closed ikit closed 3 years ago

ikit commented 3 years ago

Hello,

I'm trying to install an application with SAP and node-rfc v2 on an offline virtual machine (windows server 2016) (no connexion to Internet but access to the artifactory of the enterprise).

I successfully installed windows-build-tools, cmake, and lot of dependencies, but I'm stuck with the following problem.


$ npm install

> node-rfc@2.3.0 preinstall E:\GIT\XXXXXX\node_modules\node-rfc
> npm install cmake-js prebuild-install prebuild node-addon-api

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm notice created a lockfile as package-lock.json. You should commit this file.
+ prebuild-install@5.3.6
+ node-addon-api@3.1.0
+ cmake-js@6.1.0
+ prebuild@10.0.1
added 252 packages from 241 contributors in 51.181s

3 packages are looking for funding
  run `npm fund` for details

> node-rfc@2.3.0 install E:\GIT\XXXXXX\node_modules\node-rfc
> prebuild-install --tag-prefix -r napi || cmake-js rebuild

prebuild-install WARN This package does not support N-API version undefined
prebuild-install WARN install getaddrinfo EAI_AGAIN github.com
[
  'C:\\Program Files\\nodejs\\node.exe',
  'E:\\GIT\\XXXXXX\\node_modules\\node-rfc\\node_modules\\cmake-js\\bin\\cmake-js',
  'rebuild'
]
info TOOL Using Visual Studio 16 2019 generator.
info DIST Downloading distribution files.
http DIST       - https://nodejs.org/dist/v12.14.0/SHASUMS256.txt
ERR! OMG getaddrinfo ENOTFOUND nodejs.org
ERR! OMG getaddrinfo ENOTFOUND nodejs.org
npm WARN class-validator-jsonschema@1.3.1 requires a peer of class-transformer@^0.2.3 but none is installed. You must install peer dependencies yourself.
npm WARN class-validator-jsonschema@1.3.1 requires a peer of class-validator@^0.9.1 but none is installed. You must install peer dependencies yourself.
npm WARN routing-controllers-openapi@1.8.1 requires a peer of routing-controllers@^0.8.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-rfc@2.3.0 install: `prebuild-install --tag-prefix -r napi || cmake-js rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-rfc@2.3.0 install 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!     C:\Users\XXXXXX\AppData\Roaming\npm-cache\_logs\2021-02-01T13_44_59_311Z-debug.log```

Any idea to solve this problem ?
It is a development VM that why I'm trying to install all dependency and compiltation tools.
bsrdjan commented 3 years ago

Please try with the latest node-rfc 2.4.0, not the 2.3.0 version.

Which is your node version?

The log shows 12.14, which is not supported. Should be at least 12.17: https://github.com/SAP/node-rfc/blob/master/package.json#L11

The reason is internally used N-API v6, available from 12.17: https://nodejs.org/api/n-api.html#n_api_n_api_version_matrix

ikit commented 3 years ago

I updated node to the last LTS version: 14.15.4. updated packages so I'm now using node-rfc 2.4.0.

I also try this solution to have all packages and nm-cache on my vm.

The installation seems to wors fine. but I go the following error when I start the application:

$ npm run dev

> XXXXXX-api@2.0.123 dev E:\GIT\XXXXXX-api
> npm run start:dev

> XXXXXX-api@2.0.123 start:dev E:\GIT\XXXXXX-api
> cross-env NODE_ENV=development ts-node-dev src/api.ts

[INFO] 10:34:27 ts-node-dev ver. 1.1.1 (using ts-node ver. 9.1.1, typescript ver. 4.1.3)
info: Start API node process (ppid=10184) {"timestamp":"2021-02-02T09:34:35.167Z"}
info: WS Server has started on port 5011. {"timestamp":"2021-02-02T09:34:35.175Z"}
Error: The specified module could not be found.
\\?\E:\GIT\XXXXXX-api\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.14393"
  },
  "env": {
    "SAPNWRFC_HOME": "C:\\nwrfcsdk",
    "RFC_INI": "",
    "nwrfcsdk_lib_on_path": true
  },
  "versions": {
    "node": "14.15.4",
    "v8": "8.4.371.19-node.17",
    "uv": "1.40.0",
    "zlib": "1.2.11",
    "brotli": "1.0.9",
    "ares": "1.16.1",
    "modules": "83",
    "nghttp2": "1.41.0",
    "napi": "7",
    "llhttp": "2.1.3",
    "openssl": "1.1.1i",
    "cldr": "37.0",
    "icu": "67.1",
    "tz": "2020a",
    "unicode": "13.0"
  }
}

    at Module._extensions..node (internal/modules/cjs/loader.js:1122:18)
    at Object.nodeDevHook [as .node] (E:\GIT\XXXXXX-api\node_modules\ts-node-dev\lib\hook.js:63:13)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (E:\GIT\XXXXXX-api\node_modules\node-rfc\src\ts\wrapper\noderfc-bindings.ts:66:23)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Module._compile (E:\GIT\XXXXXX-api\node_modules\source-map-support\source-map-support.js:547:25)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Object.nodeDevHook [as .js] (E:\GIT\XXXXXX-api\node_modules\ts-node-dev\lib\hook.js:63:13)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (E:\GIT\XXXXXX-api\node_modules\node-rfc\src\ts\index.ts:7:1)
[ERROR] 10:34:36 Error: The specified module could not be found.
\\?\E:\GIT\XXXXXX-api\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.14393"
  },
  "env": {
    "SAPNWRFC_HOME": "C:\\nwrfcsdk",
    "RFC_INI": "",
    "nwrfcsdk_lib_on_path": true
  },
  "versions": {
    "node": "14.15.4",
    "v8": "8.4.371.19-node.17",
    "uv": "1.40.0",
    "zlib": "1.2.11",
    "brotli": "1.0.9",
    "ares": "1.16.1",
    "modules": "83",
    "nghttp2": "1.41.0",
    "napi": "7",
    "llhttp": "2.1.3",
    "openssl": "1.1.1i",
    "cldr": "37.0",
    "icu": "67.1",
    "tz": "2020a",
    "unicode": "13.0"
  }
}

But the sapnwrfc.node file exists at the expected location... and I try all tips on this page but I don't know what to do with these informations... something is wrong with my environment ?

$ findstr Patch %SAPNWRFC_HOME%\lib\sapnwrfc.dll
750 Patch Level 7

$ node -p "process.env".SAPNWRFC_HOME
C:\nwrfcsdk

$ npx envinfo --system --binaries
npx: installed 1 in 4.146s

  System:
    OS: Windows Server 2016 10.0.14393
    CPU: (2) x64 Intel(R) Xeon(R) Silver 4116 CPU @ 2.10GHz
    Memory: 3.25 GB / 8.00 GB
  Binaries:
    Node: 14.15.4 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.10 - C:\Program Files\nodejs\npm.CMD

$ cd $SAPNWRFC_HOME/bin
$ ./rfcexec
Error: Not all mandatory parameters specified
        Please start the program in the following way:
        rfcexec -t -a <program ID> -g <gateway host> -x <gateway service>
                -f <file with list of allowed commands> -s <allowed Sys ID>
The options "-t" (trace), "-f" and "-s" are optional.

Below further optional parameters are listed. You can find their
documentation in sapnwrfc.ini:
-on_cce <0, 1, 2> (On Character Conversion Error)
-cfit (Conversion Fault Indicator Token - the substitute symbol used if on_cce=2)
-keepalive (Sets the keepalive option. Default is 0.)
-delta <0, 1> (default 1, i.e. use delta-manager)
-no_compression (table compression, default is 0, i.e. compression is on)

but running node -p "require('node-rfc')" return the above exception.

ikit commented 3 years ago

Maybe it could help: If I remove manually the node-rfc module and redo npm install I got following logs/warning

$ npm install

> node-rfc@2.4.0 preinstall E:\GIT\XXXXXX-api\node_modules\node-rfc
> npm install cmake-js prebuild-install prebuild node-addon-api

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm notice created a lockfile as package-lock.json. You should commit this file.
+ cmake-js@6.1.0
+ prebuild-install@6.0.0
+ prebuild@10.0.1
+ node-addon-api@3.1.0
added 252 packages from 241 contributors in 54.873s

9 packages are looking for funding
  run `npm fund` for details

> node-rfc@2.4.0 install E:\GIT\XXXXXX-api\node_modules\node-rfc
> prebuild-install --tag-prefix -r napi || cmake-js rebuild

npm WARN class-validator-jsonschema@1.3.1 requires a peer of class-transformer@^0.2.3 but none is installed. You must install peer dependencies yourself.
npm WARN class-validator-jsonschema@1.3.1 requires a peer of class-validator@^0.9.1 but none is installed. You must install peer dependencies yourself.
npm WARN routing-controllers-openapi@1.8.1 requires a peer of routing-controllers@^0.8.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.1 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 1 package from 1 contributor in 64.46s

22 packages are looking for funding
  run `npm fund` for details
bsrdjan commented 3 years ago

Warnings are uncritical but rfcexec test output is a good sign:

$ cd $SAPNWRFC_HOME/bin
$ ./rfcexec

It shows that correct NWRFC SDK is installed and $SAPNWRFC_HOME/lib folder is found on PATH.

Assuming the sapnwrfc.node is where it should be, possible reasons for not loading the NWRFC SDK could be access rights to C:\nwrfcsdk\lib for the user running the test or that C:\nwrfcsdk\lib is for some reason removed from PATH.

The PATH before loading can be traced by console.log() added in node_modules\node-rfc\lib\wrapper\noderfc-bindings.js:

console.log(process.env.PATH);
try {
    exports.noderfc_binding = noderfc_binding = require("../binding/sapnwrfc");
}

Assuming access rights are not a problem, could you please trace PATH before loading and check if C:\nwrfcsdk\lib folder is on PATH ?

There was a similar issue with installation on IIS #139

ikit commented 3 years ago

I added console.log(__dirname, process.env.PATH); to the ode_modules\node-rfc\lib\wrapper\noderfc-bindings.js.

All seems good in the PATH env, and actually I'm running the code with the dev account which is admin on the VM.

The output of the console.log:

__dirname= E:\GIT\XXXXXX-api\node_modules\node-rfc\lib\wrapper
PATH= [...]C:\Users\XXXXXX\AppData\Local\Programs\Microsoft VS Code\bin;C:\nwrfcsdk\lib;C:\Program Files\CMake\bin;C:\Users\XXXXXX\AppData\Roaming\npm

But I notice something weird, the path noticed in the exception is prefixed by \\?\ ... do you know if it's normal ?

Error: The specified module could not be found.
\\?\E:\GIT\XXXXXX-api\node_modules\node-rfc\lib\binding\sapnwrfc.node
bsrdjan commented 3 years ago

\\?\ is normal, it comes like that from node stack. If I rename the sapnwrfc.dll to something else, the node -p "require('node-rfc')" fails with exactly the same error:

Error: The specified module could not be found.
\\?\C:\src\test-node\node_modules\node-rfc\lib\binding\sapnwrfc.node

Is SAP NWRFC SDK downloaded from the Service Portal and could it be that some SDK dll is missing in the lib folder? Does it look like this on your system:

PS C:\src\test-node> dir $env:SAPNWRFC_HOME/lib    

    Directory: C:\Tools\nwrfcsdk-pl6\lib

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         2/5/2020   7:31 PM       20786176 icudt50.dll
-a----         2/5/2020   7:31 PM        1573888 icuin50.dll
-a----         2/5/2020   7:31 PM        1278976 icuuc50.dll
-a----         2/5/2020   7:39 PM          65024 libicudecnumber.dll
-a----         2/5/2020   7:39 PM         159744 libsapucum.dll
-a----         2/5/2020   7:42 PM          18764 libsapucum.lib
-a----         2/5/2020   7:52 PM        7157248 sapnwrfc.dll
-a----         2/5/2020   7:52 PM          81290 sapnwrfc.lib
-a----         2/5/2020   7:50 PM       17813504 sapnwrfc.pdb

Missing dll could why rfcexec works and the app not because app might require another dll later on.

To check what is exactly happening, could you please set the NLSUI_INIT_TRACE_LEVEL env variable to "high", reproduce the issue and attach the console output:

$env:NLSUI_INIT_TRACE_LEVEL="high"
node -p "require('node-rfc')"
ikit commented 3 years ago

I have exactly the same files in my C:\nwrfcsdk\lib directory.

By crawling the web I found the same explanation than you about the error: Nodejs raise this error if the module (sapnwrfc.node) miss some dependencies.

The difficulty is to find whichs. I try to set the NLSUI_INIT_TRACE_LEVEL to high and hight but I didn't get any additional log :( ...

I also try to check the sapnwrfc.node with dependencies walker, but I have hundreds of missing dlls ... and their names don't help me see if it's critical or not :/

bsrdjan commented 3 years ago

When NLSUI_INIT_TRACE_LEVEL set to "high", the trace should be sent to console. Perhaps need to be set as system env var?

All prerequisites are mentioned here: https://github.com/SAP/node-rfc#windows and it could be that something is missing. Did you install the older version of C++ Redistributable required by SDK runtime? https://www.microsoft.com/en-US/download/details.aspx?id=40784

The process monitor should otherwise help find the missing dependency: see https://github.com/SAP/node-rfc/issues/127#issuecomment-600020359

ikit commented 3 years ago

I had to reinstall all the redistributable visual studio and now it works :D

thanks a lot for your help

bsrdjan commented 3 years ago

Welcome to the club, had to do it more than once :)