SAP / node-rfc

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

Getting Error: sapnwrfc.node is not a valid Win32 application. #284

Closed CodingQueries2023 closed 1 year ago

CodingQueries2023 commented 1 year ago

Describe the bug I have 64 bit node js installed on my system and have installed 64 bit NWRFC SDK but I am still getting the error "\?\C:...\node_modules\node-rfc\lib\binding\sapnwrfc.node is not a valid Win32 application".

To Reproduce Describe how the node-rfc is installed, like locally or globally and using npm install or build from source. I have installed node-rfc locally from https://www.npmjs.com/package/node-rfc , using the command "npm i node-rfc".

envinfo echo2 version

Environment

node-rfc
bsrdjan commented 1 year ago

The output of node -p "require('node-rfc').environment" shows that SAP NWRFC SDK "lib" folder is apparently not on PATH. The loader can't therefore find and load SAP NWRFC libraries.

"nwrfcsdk_lib_on_path": false

It should be fixed by adding c:\nwrfcsdk\lib to PATH, as described in installation#windows

CodingQueries2023 commented 1 year ago

Thank you for your reply. The PATH in the environment variable shows as - image But the error still exists.

bsrdjan commented 1 year ago

Can you do the following test and post the output

cd \nwrfcsdk\bin
rfcexec
CodingQueries2023 commented 1 year ago

After running the command I am getting a pop-up which says "The code execution cannot proceed because MSVCP120.dll was not found. reinstalling the program may fix this problem".

bsrdjan commented 1 year ago

Microsoft C Runtime DLLs version 12.0 (Visual C++ 2013) is a prerequisite for SAP NWRFC SDK. Is it installed on your system?

https://github.com/SAP/node-rfc#windows

CodingQueries2023 commented 1 year ago

No, I didn't have it on my system so I installed it. And now I am getting the following output- image

bsrdjan commented 1 year ago

it is correct output installation.md#verify-sap-nwrfc-sdk-installation

The node-rfc should work as well :)

CodingQueries2023 commented 1 year ago

Unfortunately I am still getting the same error. image

I also created a fresh folder and did npm init -y and then installed node-rfc but still I am getting the error.

bsrdjan commented 1 year ago

Can you run the Windows Process monitor, to check which library exactly fails to load?

Just start the Process Monitor and run the following command to reproduce. Similar issue discussed here: https://github.com/SAP/node-rfc/issues/115#issuecomment-570248671

node -p "require('c:\node-rfc\node_modules\node-rfc\lib\binding\sapnwrfc.node')" 
CodingQueries2023 commented 1 year ago

I am getting something like this- image

bsrdjan commented 1 year ago

can you find sapnwrfc.dll and any error in log? The status different from SUCCESS ?

CodingQueries2023 commented 1 year ago

I could not find the sapnwrfc.dll and apart from the SUCCESS there is only BUFFER OVERFLOW and NAME NOT FOUND.

bsrdjan commented 1 year ago

No idea what could be the problem. Are you using standard Windows system ? Which version/edition?

I just tested as follows:

  1. Created fresh new Windows 11 Professional system, in VMare Fusion
  2. Installed Microsoft C Runtime DLLs version 12.0, install
  3. Installed nvm for Windows and using nvm installed current node 19
  4. Created test folder and tested
npm init -y
npm install node-rfc
node -p "require('node-rfc')"

Can you check if C:...\node_modules\node-rfc\lib\binding\sapnwrfc.node exists ? What is the output of direct require of that file:

cd ... to sapnwrfc.node folder
node -p "require('./sapnwrfc.node')" 

Fresh new install should work. Some users (years ago) reported that was the only solution for them after MC C++ DLLs installed after some other libraries.

CodingQueries2023 commented 1 year ago

I am using windows 10, Version 21H2. image

I checked and yes the file sapnwrfc.node at C:...\node_modules\node-rfc\lib\binding\sapnwrfc.node exists.

image

Below is the output of the command node -p "require('./sapnwrfc.node')" ---

image

bsrdjan commented 1 year ago

Something is apparently wrong with the installation:

1) nwrfcsdk_lib_on_path in environment is shown as false and should be true 2) The sapnwrfc.node file size in File Explorer is 276 KB and on test system is 224KB

Screenshot 2023-04-03 at 14 57 15

Could you please create fresh new folder and post the full log

mkdir test
cd test
npm init -y

# show SAPNWRFC_HOME and PATH
echo $env:SAPNWRFC_HOME
echo $env:PATH 
# or echo %PATH% ...

npm install node-rfc

node -p "require('node-rfc')"

Are you using some sort of "special" Windows installation, like running in virtual machine or similar hosted environment?

Could you please also check the file type of sapnwrfc.node, using TrID or similar Windows utility ?

CodingQueries2023 commented 1 year ago

image

image

image

Yes, I am running it on a virtual machine.

After this fresh installation ------- image

bsrdjan commented 1 year ago

Thank you @CodingQueries2023. Could you please also post the full console output as per my last comment

mkdir test
cd test
npm init -y
npm install node-rfc

Also

Could you please also check the file type of sapnwrfc.node, using TrID or similar Windows utility ?

CodingQueries2023 commented 1 year ago
full1

For some reason I couldn't run TrID, is there any other software that might help cause?

bsrdjan commented 1 year ago

For some reason I couldn't run TrID, is there any other software that might help cause?

I can check, could you please attach your sapnwrfc.node file here?

Also run npm install --production node-rfc --loglevel verbose in fresh new test folder and attach the full installation log to message.

CodingQueries2023 commented 1 year ago

binding.zip

fullnew1 fullnew2 fullnew3 fullnew4
bsrdjan commented 1 year ago

sapnwrfc.node file from binding.zip is Linux executable and can't run on Windows. It causes the loading error: "sapnwrfc.node is not a valid Win32 application"

The executable file format can be determined also by prefix shown in plain text editor, like notepad.exe. The prefix of your sapnwrfc.node is ELF and for Windows it should be MZ.

sapnwrfc-node

Also the size of that Linux sapnwrfc.node differs from what is shipped in latest node-rfc release.

Your NPM is apparently configured for custom registry, getting corrupted installation package from there.

CodingQueries2023 commented 1 year ago

Thank you @bsrdjan for your reply.

I can't change the registry but is there a way to get around this and fix the issue?

bsrdjan commented 1 year ago

only manual workaround. sapnwrfc.node executables for supported platforms are attached to node-rfc GitHub releases. You can

  1. Navigate to node-rfc latest GitHub release and download the Windows "asset" from there: node-rfc-v2.7.1-napi-v8-win32-x64.tar.gz
  2. Unpack the asset archive and replace your Linux sapnwrfc.node with sapnwrfc.node from the archive

You can also use this sapnwrfc.node.zip for Windows, for node-rfc 2.7.1

It should work but there could be also issues in case the rest of the package from custom registry is older node-rfc version, possibly incompatible with the latest sapnwrfc.node executable.

Why not install from standard registry and avoid the risk ?

CodingQueries2023 commented 1 year ago

I followed the step 1 and I am getting the following output, I am not sure but I think it works, could you please confirm. image

bsrdjan commented 1 year ago

looks correct now

bsrdjan commented 1 year ago

@CodingQueries2023, what type of virtual machine are you using and can you describe how your Windows system is hosted?

It could help other users with similar setup if we can find out why Linux binaries are fetched instead of Windows.

CodingQueries2023 commented 1 year ago

Hi @bsrdjan On server I am getting the error RFC_COMMUNICATION_FAILURE and it is automatically trying to connect to our IP with PORT 3300, which is a wrong port. My correct PORT is 3629 but instead of 3629 it is trying to connect to 3300 and is getting failed to connect to. In my docker file I have mentioned the PORT 3629 and not 3300. Is there anything that you can suggest about the issue?

bsrdjan commented 1 year ago

Could you please create another issue for communication error?

You can also try node-rfc pre-release 3.0.0-rc.1. The packaging is changed and node-rfc contains binaries for all platforms, not fetching them from Github any more.

CodingQueries2023 commented 1 year ago

Sure I will create a new issue for communication error