SAP / node-rfc

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

Error - rfc.Client is not a function #10

Closed donaldhook closed 8 years ago

donaldhook commented 8 years ago

I am receiving the following error trying to create the client. Not sure what I have defined incorrectly.

Thanks for your help

Code

.... // Define the SAP Configuration var SAPconfig = { user: 'xxx', passwd: 'xxx', ashost: 'xxx', sysnr: '010', client: '11' };

var rfc = require('node-rfc'); var client = new rfc.Client(SAPconfig, true); console.log('\ RFC Client Lib Version: ' + client.getVersion());

Console Log

var client = new rfc.Client(SAPconfig, true); ^

TypeError: rfc.Client is not a function at Object. (c:\Boelter Applications\BoelterIntegrationServer\server.js:57:14) at Module._compile (module.js:399:26) at Object.Module._extensions..js (module.js:406:10) at Module.load (module.js:345:32) at Function.Module._load (module.js:302:12) at Module.runMain as _onTimeout at Timer.listOnTimeout (timers.js:93:15)

bsrdjan commented 8 years ago

The code looks correct. Which nodejs version are you using and on which platform (Linux/Windows) ?

donaldhook commented 8 years ago

I am using node 5.2 on Windows 10

donaldhook commented 8 years ago

I have a dot there in the statement ...rfc.Client

On Tue, Dec 15, 2015 at 6:10 AM, heri16 notifications@github.com wrote:

rfc.Client. Missed a dot there

— Reply to this email directly or view it on GitHub https://github.com/SAP/node-rfc/issues/10#issuecomment-164745679.

bsrdjan commented 8 years ago

node 5.2 was not supported and I just pushed the fix, in the master branch, tested on Linux only.

To test on Windows the node-rfc binary must be built from source, following the "Build from source" section of the documentation. Did you build the binary from source, from the current master ?

donaldhook commented 8 years ago

I did not... I will try it out and let you know the results. Thanks for your time and help!

On Wed, Dec 16, 2015 at 6:24 AM, Srdjan Boskovic notifications@github.com wrote:

node 5.2 was not supported and I just pushed the fix, in the master branch, tested on Linux only.

To test on Windows the node-rfc binary must be built from source, following the "Build from source" section of the documentation. Did you build the binary from source, from the current master ?

— Reply to this email directly or view it on GitHub https://github.com/SAP/node-rfc/issues/10#issuecomment-165091161.

donaldhook commented 8 years ago

Ok, need a bit more clarity on how to compile from source to create the .node file for Windows. Where do i download the source to? Where do I execute node-gyp build from?

Thanks and sorry for the inconvenience

bsrdjan commented 8 years ago

No inconveniences at all, no worries. The build from source is described here. Basically, you need to clone this repository and cd to root folder, default node-rfc. Then check the prerequisites and follow the steps in the documentation:

git clone https://github.com/SAP/node-rfc.git
cd node-rfc
node-gyp configure --msvs_version=2013
node-gyp build

Visual Studio 2015 worked with nodejs 4.2.0 and I suppose it should work with nodejs 5.2.0 as well, but did not test that combination.

Before you start building, the path to Visual Studio shall be configured in binding.gyp.

You also need SAP NW RFC Library installed, as described in the documentation.

SAP NW RFC Library is available as 32 bit and 64 bit and Windows platforms today are usually 64 bit. If you use 64 bit platform and 64 bit RFC lib, the nodejs shall run in 64 bit mode as well. That is unfortunately not always the default and If you use node version manager nvm for example, you may use the command nvm arch, to check the current setting. More details in "Usage" section of https://github.com/coreybutler/nvm-windows

Hope this helps, to start at least.

donaldhook commented 8 years ago

Thank you for all your help!! I am getting a connection refused so now I can start to address that.

Thanks!!

LOCATION CPIC (TCP/IP) on local host PWKSRV29 with Unicode ERROR partner '10.1.21.40:3300' not reached TIME Thu Dec 17 18:50:42 2015 RELEASE 721 COMPONENT NI (network interface) VERSION 40 RC -10 MODULE nixxi.cpp LINE 3283 DETAIL NiPConnect2: 10.2.20.40:3300 SYSTEM CALL connect ERRNO 10061 ERRNO TEXT WSAECONNREFUSED: Connection refused COUNTER 2 ] code: 1, key: 'RFC_COMMUNICATION_FAILURE' }

bsrdjan commented 8 years ago

'partner not reached' looks like network issue. In your connection parameters the client is set to '11', should be three digits, you can also send me the connection params to check. Using SAP network utility niping, you can check the network connectivity to ABAP server, independent of the node-rfc: niping -CH <server ip and port>. More details on this in OSS note 500235, scn.

donaldhook commented 8 years ago

WIll do... thank you for all your great help!!

On Fri, Dec 18, 2015 at 12:31 AM, Srdjan Boskovic notifications@github.com wrote:

'partner not reached' looks like network issue. In your connection parameters the client is set to '11', should be three digits, you can also send me the connection params to check. SAP network utility niping to check the network connectivity to ABAP server, independent of the node-rfc: niping -CH . More details on this in OSS note 500235 http://service.sap.com/sap/support/notes/500235, scn http://wiki.scn.sap.com/wiki/display/ABAP/NIPING.

— Reply to this email directly or view it on GitHub https://github.com/SAP/node-rfc/issues/10#issuecomment-165689192.

bsrdjan commented 8 years ago

Windows 64 bit builds published in branches 4.2.3 and 5.3.0

GeorgeMacintoshJr commented 6 years ago

Hello @donaldhook I've followed the instruction of @bsrdjan but still i'm getting error. image

Were you able to connect to SAP system using node-rfc? I'm new to SAP and I'm having a really hard time on setting up.

Thanks for your help.

donaldhook commented 6 years ago

George

There are 2 dll's that you need to install in the c:\windows\system32 directory ... sapjco3.dll and sapnwrfc.dll

This was a pain to setup, so you are not alone. I ended up going to Spring Boot to implement my project....

bsrdjan commented 6 years ago

@GeorgeMacintoshJr, the error message is telling the compiler is not finding sapnwrfc.h header file. The location where the compiler is looking for this file is defined in binding.gyp. To find the file, the env variable SAPNWRFC_HOME shall point to the root folder path of SAPNWRFC library. Further details on SAPNWRFC lib installation are documented here. Could you please check if this helps?

donaldhook commented 6 years ago

I seem to recall there was an option as to which VStools version to use... vs2015 vs2013 ... did you see that anywhere?

GeorgeMacintoshJr commented 6 years ago

Hello @donaldhook Your project aim is to make a connection from a non-SAP system to a SAP system and retrieve data? Were you able to make the connection using the SAP or do you recommend using other method?

Thank you. I'm so glad to hear from you since you were so involved on this.

GeorgeMacintoshJr commented 6 years ago

Hello @bsrdjan I already set my env variable image

After that when executing node-gyp configure --msvs_version=2015 I was getting this error image

what I did to get rid of the error Under binding.gyp

  1. Change the <(module_name) to "rfc"
  2. Change the <(module_path) to "." image

image

Next I execute node-gyp build,the output is 1 warning and 1 error image now to overcome the error what I did was Under rfc.vcxproj

  1. Change sapnwrfc.lib to C:\nwrfcsdk\lib\sapnwrfc.lib
  2. Change libsapucom.lib to C:\nwrfcsdk\lib\libsapucum.lib because it seems like it cannot find the C:\nwrfcsdk\lib

So after that I was getting this output image

Now I don't know how to proceed. I'm afraid the warning: MSB8012 can cause incorrect behavior. Also how do test the node-rfc ?

Do I execute the mocha demo inside the node-rfc/demo folder? image

Thanks and sorry for the inconvenience. I'd really appreciate any help.

bsrdjan commented 6 years ago

just a small hint, the env variable SAPNWRFC_HOME should point to the root folder of SAPNWRFC lib, thus without \lib suffix. Starting from that folder, both includes and libraries can be referenced in binding.gyp.

mocha tests are executed against one SAP internal test system and some RFMs (Remote Function Modules) used in these tests may not exist in your test system. I would recommend starting from the simple test, like in README Getting Started, just adapt connection parameters. Mocha tests can be used as examples to build own tests, in similar manner.

Regarding question which connection method to use from non-SAP to SAP system, it depends on system release and mostly on use-case and application. With SAP systems with HANA, the node-hdb can be used for the integration at table level. In landscapes with SAP NW GATEWAY and ODATA services, that method can be used as well. RFM (node-rfc) integration works with any system, new or old and still the fastest way for executing SAP business logic from nodejs. There are also other methods, like WS-SOAP or IDocs and it depends on use-case which one to use.

GeorgeMacintoshJr commented 6 years ago

Thanks @bsrdjan I removed the \lib suffix, after that I don't have to specify the path under rfc.vcxproj.

image To perform a connection I have to perform 3 things

  1. Create a client with valid logon credentials
  2. Connect to NetWeaver system
  3. Invoke a remote enabled ABAP function module from node

  4. I already create a client on SAP.
  5. Connect to NetWeaver System meaning install the NWRFC SDK?
  6. To call the function which is remote enabled on Application Server?

Do I have to create another folder and create a js file then paste this code image

Or I can just use the demo.js? Sorry, I'm really confuse on how to perform a connection on SAP.

bsrdjan commented 6 years ago

Now I see, the naming and comments in this source could be better, will enhance.

Once compiled, It is enough to copy and run the demo.js, like node demo. If the node-rfc module not found, it shall be referenced either by node-pre-gyp or direct, like in dev branch test.js.

GeorgeMacintoshJr commented 6 years ago

Oh thanks @bsrdjan, the naming are fine I just enumerate what I have done for each item. So after executing the node-gyp build I just change directory to the demo folder

C:\Users\Owner\Desktop\Sample\node-rfc> cd demo

and run node demo. But before that I have to add these line of code on demo.js

var should = require("should"); var binary = require('node-pre-gyp'); var path = require('path'); var rfc_path = binary.find(path.resolve(path.join(__dirname,'../package.json'))); var rfc = require(rfc_path);

otherwise I will get an error of node-rfc module not found.

Thank you @bsrdjan, I just need to clarify things for the benefits also of other developers. Because I can see that this module has great potentials.