SAP / node-rfc

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

Collision with SAPLogon SAPGUI client; error: The specified procedure could not be found. #226

Closed nikmalenovic closed 2 years ago

nikmalenovic commented 2 years ago

Describe the bug unable to execute installation test node -p "require('node-rfc')".

To Reproduce Windows 2012 R2 x64 (Microsoft Windows [Version 6.3.9600]). Installed Visual C++ redistributable 2013 x64. Installed SAP NW RFC SDK 7.50 (750 Patch Level 8). Installed node.js LTS 14 (14.17.3) along with tooling. The SAPNWRFC_HOME=c:\nwrfcsdk. PATH has c:\nwrfcsdk\lib. The rfcexec (c:\nwrfcsdk\bin\rfcexec.exe) runs without errors. Install node-rfc into global cache (npm -g i node-rfc) followed by link to my current project (npm link node-rfc). Executed node -p "require('node-rfc')"

Screenshots Install and error transcript:

C:\MYPROJECT>npm -g i node-rfc

> node-rfc@2.5.1 preinstall %APPDATA%\npm\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 WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-
random for details.
%APPDATA%\npm\cmake-js -> %APPDATA%\npm\node_modules\cmake-js\bin\cmake-js
%APPDATA%\npm\prebuild-install -> %APPDATA%\npm\node_modules\prebuild-install\bin.js
%APPDATA%\npm\prebuild -> %APPDATA%\npm\node_modules\prebuild\bin.js
+ node-addon-api@4.0.0
+ prebuild-install@6.1.3
+ prebuild@10.0.1
+ cmake-js@6.2.1
added 385 packages from 248 contributors in 90.71s

> node-rfc@2.5.1 install %APPDATA%\npm\node_modules\node-rfc
> prebuild-install --tag-prefix -r napi || cmake-js rebuild

+ node-rfc@2.5.1
added 3 packages from 79 contributors in 93.17s

C:\MYPROJECT>npm link node-rfc
C:\MYPROJECT\node_modules\node-rfc -> %APPDATA%\npm\node_modules\node-rfc

C:\MYPROJECT>node -p "require('node-rfc')"
%APPDATA%\npm\node_modules\node-rfc\lib\wrapper\noderfc-bindings.js:45
    throw ex;
    ^

Error: The specified procedure could not be found.
\\?\%APPDATA%\npm\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": "6.3.9600"
  },
  "env": {
    "SAPNWRFC_HOME": "c:\\nwrfcsdk",
    "RFC_INI": "",
    "nwrfcsdk_lib_on_path": true
  },
  "versions": {
    "node": "14.17.3",
    "v8": "8.4.371.23-node.67",
    "uv": "1.41.0",
    "zlib": "1.2.11",
    "brotli": "1.0.9",
    "ares": "1.17.1",
    "modules": "83",
    "nghttp2": "1.42.0",
    "napi": "8",
    "llhttp": "2.1.3",
    "openssl": "1.1.1k",
    "cldr": "39.0",
    "icu": "69.1",
    "tz": "2021a",
    "unicode": "13.0"
  }
}

    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1144:18)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (%APPDATA%\npm\node_modules\node-rfc\lib\wrapper\noderfc-bindings.js:36:49)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (%APPDATA%\npm\node_modules\node-rfc\lib\index.js:16:14)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)

C:\MYPROJECT> node --version
v14.17.3

C:\MYPROJECT>ver

Microsoft Windows [Version 6.3.9600]

C:\MYPROJECT>findstr Patch %SAPNWRFC_HOME%\lib\sapnwrfc.dll
750 Patch Level 8

C:\MYPROJECT>set|findstr rfc
PATH=...;c:\nwrfcsdk\lib;...
SAPNWRFC_HOME=c:\nwrfcsdk

C:\MYPROJECT>c:\nwrfcsdk\bin\rfcexec.exe
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)

Environment

Additional context none

bsrdjan commented 2 years ago

I could not exactly reproduce and observe slightly different behaviour on test system:

global

npm -g i node-rfc

local

npm init -y
node -p "require('node-rfc').environment" # error
Error: Cannot find module 'node-rfc'

node-rfc is initially not found because NODE_PATH was not set and global modules can't be required. Once it is set, the node-rfc works fine:

npm -g root
C:\Tools\nodejs\node_modules
set NODE_PATH=C:\Tools\nodejs\node_modules
node -p "require('node-rfc').environment" # ok

Is NODE_PATH set on your system and to which path?

nikmalenovic commented 2 years ago

The NODE_PATH is not set. I set it to my npm -g root location and it made no difference.

bsrdjan commented 2 years ago

hm, not sure what exactly goes wrong because I could not reproduce.

Could you eventually try with new created project folder ? Eventually with another node version, just in case ...?

Here what works for me:

mkdir i226
cd i226
npm init -y

npm -g install node-rfc

# does not work w/o npm link
node -p "require('node-rfc').environment"
  ^
Error: Cannot find module 'node-rfc'

# works after npm link
npm link node-rfc
C:\src\i226\node_modules\node-rfc -> C:\Tools\nodejs\node_modules\node-rfc
node -p "require('node-rfc').environment"
{
  platform: { name: 'win32', arch: 'x64', release: '10.0.19042' },
  env: {
    SAPNWRFC_HOME: 'C:\\Tools\\nwrfcsdk',
    RFC_INI: '',
    nwrfcsdk_lib_on_path: true ...

# does not work after npm unlink
npm unlink node-rfc
npm WARN i226@1.0.0 No description
npm WARN i226@1.0.0 No repository field.
}
removed 1 package in 0.592s
found 0 vulnerabilities

node -p "require('node-rfc').environment"
  ^
Error: Cannot find module 'node-rfc'

# works with NODE_PATH
$env:NODE_PATH="C:\Tools\nodejs\node_modules"
node -p "require('node-rfc').environment"
{
  platform: { name: 'win32', arch: 'x64', release: '10.0.19042' },
  env: {
    SAPNWRFC_HOME: 'C:\\Tools\\nwrfcsdk',
    RFC_INI: '',
    nwrfcsdk_lib_on_path: true ...
nikmalenovic commented 2 years ago

Could you eventually try with new created project folder ? Eventually with another node version, just in case ...?

I tried with both LTS 14 and latest 16. Also tried both a new project with a link and a new project without global install. All attempts ended up with identical failure.

I tried a third "clean" 2012 R2. Installed nodejs LTS 14.17.3 without tools (choco, build tools, python). DIdn't install visual studio c++ build environment, cmake. Installed MSVC 2013 x64 redistributable, NW RFC SDK 7.50.8 into C:\nwrfcsdk, set SAPNWRFC_HOME=c:\nwrfcsdk, added %SAPNWRFC_HOME%\lib to PATH. Installed node-rfc into C:\temp, and ran node -p "require('node-rfc').environment" and it worked. Since systems are identical, why would one work and not the other? your guess is as good as mine - it'd be nice to get better trace diagnostics to identify what is the root cause of the issue.

And yes, I did try cleaning up the broken machines, re-installing from scratch like the one that works, but it produced identical failed result again.

bsrdjan commented 2 years ago

The installation sequence of Windows redistributables and dependencies sometimes matters on Windows. Few users reported (over years) that fresh new Windows installation was the only way to resolve. It might be an issue with dependencies but hard to guess without further analysis.

To find out what is exactly failing on affected system, could you try to activate the Windows Process Monitor, run the node -p "require('node-rfc').environment to reproduce the issue and check Process Monitor logs afterwards ? The log should show problematic library, like here for example: https://github.com/SAP/node-rfc/issues/127#issuecomment-600020359.

SAP test program rfcexec.exe does not load all SAP NWRFC SDK binaries when started w/o parameters and is therefore not 100% proof that all SDK binaries and dependencies are correctly installed. Process Monitor should help localise the problem.

Could you please also test if it works with node-rfc 2.4.2 ? There is similar issue starting from node-rfc 2.4.3 but not sure if related.

nikmalenovic commented 2 years ago

procmon64 did it's job - filtered it by Process Name = node.exe - it showed it was loading NW RFC SDK DLLs from C:\Windows\System32 - after a bit of poking had to remove sapnwrfc.dll (along with libicudecnumber.dll and libsapucum.dll) from C:\Windows\System32 and C:\Windows\SysWOW64 and viola - it works. Closing. Thanks!

bsrdjan commented 2 years ago

Glad it is solved :) The https://github.com/SAP/node-rfc/issues/229 looks similar and perhaps more users are affected.

Can you maybe find out know how the RFC SDK landed at C:\Windows\System32 and C:\Windows\SysWOW64 ? These folders are apparently for 32 bit libraries on 64 bit system and it looks less likely the SDK is intentionally copied there?

If some recently installed package installed RFC SDK automatically, at these locations it would be good to find out which one.

nikmalenovic commented 2 years ago

Can you maybe find out know how the RFC SDK landed at C:\Windows\System32 and C:\Windows\SysWOW64 ?

I uninstalled almost every package (except SAP GUI) on the system in attempt to clean it up and none of the installers removed those files. it's possible it was an ad hoc manual action at some point in the past attempt to make something else work. At least this serves as a good troubleshooting knowledge base exemplar for the next poor soul that gets the equivalent of "check engine" light.

bsrdjan commented 2 years ago

it's possible it was an ad hoc manual action at some point in the past attempt to make something else work.

Not sure about that. The same issue is reported on few other Windows notebooks with SAP standard Windows image, in issue #229. We suspect the error in installation procedure of some package and still investigate the root cause.

Is the Windows image on your notebook maybe a corporate/organization image? If yes, can you check if the same happens on some other notebook with SAP GUI installed?

bsrdjan commented 2 years ago

@nikmalenovic

After checking more affected systems, the root cause is the collision of SAP Logon Client installation (SAPGUI) with node-rfc installation.

The standard node-rfc installation requires the latest SAP NWRFC SDK, copied to local folder and added to PATH.

SAP Logon Client also installs the SAP NWRFC SDK but in %WinSysDir%, which is C:\Windows\system32 for 64-bit processes and C:\Windows\SysWoW64 for 32-bit processes. According to Windows DLL Search Order, these folders are searched first and when RFC SDK found there, the RFC SDK version on PATH does not matter, is not used.

The problem occurs when the RFC SDK version installed by SAPGUI is older than the version required for node-rfc and we try find out when and how that happens.

We collect more info from affected systems and it would help if you can send me:

bsrdjan commented 2 years ago

Please also check if only 32-bit 2013 VSC++ redistributable is installed. The 64-bit version (x64) must not be installed:

32-bit-VSC++
nikmalenovic commented 2 years ago

Please also check if only 32-bit 2013 VSC++ redistributable is installed. The 64-bit version (x64) must not be installed: ...

That's really problematic because ADT (ABAP Development Tools) require the x64 version of the 2013 VSC++ redistributable. I installed both (x32+x64) version of 2013 VSC++ on a fresh Windows 10, along with SAP NW RFC SDK, and fresh install of node 16 and eclipse 2021 with ADT tools, and it seems both eclipse (ABAP projects) and node-rfc (RFC calls from node) work like a charm. I do have SAP GUI 7.7 as well on this fresh system and yes, it did install the sapnwrfc.dll in C:\Windows\SysWOW64.

bsrdjan commented 2 years ago

yes, both 32 and 64 bit redistributable must co-exist, removing one of them is not the solution. The issue on my test systems was something else and you use 64-bit Windows and 64-bit node, no need to install the 32-bit redistributable.

If I understand correctly, the re-installation of above mentioned packages fixed the issue?

Did you maybe re-installed or updated SAPGUI as well?

bsrdjan commented 2 years ago

Please reopen if support still needed.