SAP / node-rfc

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

"The specified module could not be found" when loaded in app running under IIS #139

Closed steve-king-ky closed 4 years ago

steve-king-ky commented 4 years ago

Today a test server was setup and I moved a project I'm working there. It's a Node application using Express. When I tested an endpoint it failed with:

Application has thrown an uncaught exception and is terminated:
Error: The specified module could not be found.

\\?\C:\inetpub\wwwroot\PersonnelApps\b50api\node_modules\node-rfc\lib\binding\sapnwrfc.node

 The SAP NW RFC SDK could not be loaded, check the installation: http://sap.github.io/node-rfc/install.html#sap-nw-rfc-sdk-installation
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1206:18)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (C:\inetpub\wwwroot\PersonnelApps\b50api\node_modules\node-rfc\lib\wrapper\sapnwrfc-client.js:6:15)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (C:\inetpub\wwwroot\PersonnelApps\b50api\node_modules\node-rfc\lib\index.js:6:10)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)

However, when I go to the command-line and run the same code that connects to SAP via node-rfc in a small .js file using it works just fine so there's something about the context of it running under IIS that's causing the issue although I've no idea.

BTW, the line: const rfc = require("node-rfc") when running in a script under IIS, is enough to cause the program to crash.

Any suggestions? This is driving me crazy...

bsrdjan commented 4 years ago

Did you check prerequisites on IIS: https://github.com/SAP/node-rfc#prerequisites ?

Also if SAP NWRFC SDK is correctly installed, by running rfcexc.exe: http://sap.github.io/node-rfc/install.html#test ?

steve-king-ky commented 4 years ago

@bsrdjan Yes, it appears to have been installed correctly. If I execute a script from the command-line that uses node-rfc it works perfect. This error only happens when executing under IIS for some reason.

bsrdjan commented 4 years ago

Could it be that IIS for some reason can't access the SAP NNRFC SDK path?

To verify, I would try something like this on IIS:

// verify the IIS user
console.log(os.userInfo());
/*
{
  uid: 501,
  gid: 20,
  username: 'bsrdjan',
  homedir: '/Users/bsrdjan',
  shell: '/usr/local/bin/zsh'
}
*/

// verify SAP NWRFC SDK is on PATH
console.log(process.env.PATH)

// verify IIS can read SAP NWRFC SDK libs
// do some readfile from SAP NWRFC SDK lib here ...
steve-king-ky commented 4 years ago

Great idea and running it led to an unusual discovery. The user has access but the value returned by process.env.PATH does NOT contain the path to nwrfcsdk - even though it's in the PATH environment variable (Windows) on both the system and the user.

Even more odd, if I run node.exe and run the following code:

process.env.PATH

I do see the path to the SDK listed. I restarted the IIS server but it still won't pull back the correct path. I'm not sure where it's pulling it from or if it's perhaps truncating the path?

bsrdjan commented 4 years ago

Web servers restrict web sites' to local host paths. IIS could be configured the same way, using virtual directories etc. Perhaps this helps: https://stackoverflow.com/questions/14611015/iis7-accessing-network-share

vullnet-kurti commented 4 years ago

@bsrdjan I am running in the same problem. I downloaded windows x64 binary from here https://github.com/SAP/node-rfc/releases/tag/v1.2.0, and I'm getting the same error:

Error: The specified module could not be found.

Also if SAP NWRFC SDK is correctly installed, by running rfcexc.exe: http://sap.github.io/node-rfc/install.html#test ?

Also checked this. It is correctly installed.

This is from a simple .js file that imports node-rfc: const rfc = require("node-rfc")

I logged process.env.PATH, and the SAP NWRFC SDK path gets listed.

Any idea why this might happen?

Thanks.

steve-king-ky commented 4 years ago

As far as I can tell, it’s a versioning issue. I was able to get node-rfc to work with v12.18.0 (the latest version of node when I downloaded it recently) and node-rfc v. 1.0.0.

I am running in the same problem. I downloaded windows x64 binary from here https://github.com/SAP/node-rfc/releases/tag/v1.2.0https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_SAP_node-2Drfc_releases_tag_v1.2.0&d=DwMCaQ&c=jvUANN7rYqzaQJvTqI-69lgi41yDEZ3CXTgIEaHlx7c&r=0cnh2ele5QovaKlZoZ8ilgyH2T2Y09GAxa8EnMZKmP8&m=C08JkxWU62UoShF5k1xAIODy0pqtNZxZ4qJK947fE0Y&s=0MyxZa8ST99tXlbsQ4EXx5fY4ME4-7C4BDEjOP_0cv0&e=, and I'm getting the same error:

Error: The specified module could not be found.

This is from a simple .js file that imports node-rfc: const rfc = require("node-rfc")

I logged process.env.PATH, and the SAP NWRFC SDK path gets listed.

Any idea why this might happen?

bsrdjan commented 4 years ago

Sorry for the longer waiting here. I don't see a difference in node-rfc version, causing the issue.

Could it be the authorisation problem? Could it be that IIS is running with another user account, which does not have access to NWRFC SDK ?

steve-king-ky commented 4 years ago

No worries - thank you so much for your interest in this post, by the way. I do not think that was the issue. Once I paired version 1.0.0 of the node-rfc packge with the latest version of node.js it worked fine.

bsrdjan commented 4 years ago

Thanks for the update, let close the issue then. I also sent one message via LinkedIn.