SAP / node-rfc

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

"MODULE_NOT_FOUND" when installing node-rfc locally in a docker environment #256

Closed Franco-Figueredo closed 2 years ago

Franco-Figueredo commented 2 years ago

Describe the bug "MODULE_NOT_FOUND" error when trying to execute some SAP Function Module such as RFC_TRANSACTION_CALL.

To Reproduce Install node-rfc locally, not from npm. Download it using InvokeWebrequest (https://github.com/SAP/node-rfc/issues/166#issuecomment-681901627) and then change directory to node-rfc-main. There, use npm install.

Screenshots Took this screenshot to show that everything's installed correctly. Ran all the commands listed here: https://github.com/SAP/node-rfc/blob/main/doc/installation.md image

Environment image

Additional context Full error when running the script to execute some SAP Function Module such as RFC_TRANSACTION_CALL:

/usr/src/app/noderfc-master/node-rfc-main/lib/wrapper/noderfc-bindings.js:42
throw err;
^

Error: Cannot find module '../binding/sapnwrfc'

Require stack:
- /usr/src/app/noderfc-master/node-rfc-main/lib/wrapper/noderfc-bindings.js
- /usr/src/app/noderfc-master/node-rfc-main/lib/index.js
- /usr/src/app/index.js

environment: {
  "platform": {
    "name": "linux",
    "arch": "x64",
    "release": "5.10.16.3-microsoft-standard-WSL2"
  },
  "env": {
    "SAPNWRFC_HOME": "/usr/src/app/sap/nwrfcsdk",
    "RFC_INI": ""
  },
  "versions": {
    "node": "16.14.2",
    "v8": "9.4.146.24-node.20",
    "uv": "1.43.0",
    "zlib": "1.2.11",
    "brotli": "1.0.9",
    "ares": "1.18.1",
    "modules": "93",
    "nghttp2": "1.45.1",
    "napi": "8",
    "llhttp": "6.0.4",
    "openssl": "1.1.1n+quic",
    "cldr": "40.0",
    "icu": "70.1",
    "tz": "2021a3",
    "unicode": "14.0",
    "ngtcp2": "0.1.0-DEV",
    "nghttp3": "0.1.0-DEV"
  }
}

    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/usr/src/app/noderfc-master/node-rfc-main/lib/wrapper/noderfc-bindings.js:37:46)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/usr/src/app/noderfc-master/node-rfc-main/lib/index.js:20:14)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/src/app/noderfc-master/node-rfc-main/lib/wrapper/noderfc-bindings.js',
    '/usr/src/app/noderfc-master/node-rfc-main/lib/index.js',
    '/usr/src/app/index.js'
  ]
}

My script has the requirement of node-rfc the following way: const addon = require('./noderfc-master/node-rfc-main/lib/index');

bsrdjan commented 2 years ago

What are exactly the installation steps? This sounds wrong:

Download it using InvokeWebrequest (https://github.com/SAP/node-rfc/issues/166#issuecomment-681901627) and then change directory to node-rfc-main. There, use npm install

The npm install will install node-rfc dependencies and rebuild the node-rfc. It will not install it on your system or project.

It should be:

Download it using InvokeWebrequest (https://github.com/SAP/node-rfc/issues/166#issuecomment-681901627) and then change directory to working directory (where the package.json is) and use npm install /path/to/node-rfc-main

or the node-rfc can be installed globally: npm -g install /path/to/node-rfc-main

Here one working ubuntu docker, as a reference: https://github.com/SAP/fundamental-tools/blob/main/docker/ubuntu-qa.Dockerfile

Franco-Figueredo commented 2 years ago

The installation steps are (locally and directly from Visual Studio Code, not in docker):

1- Download the master branch and unzip it to 'node-rfc-master' folder. 2- I run the command npm install /path/to/node-rfc-master and the installation runs without problems. 3- I try to run index.js with this line const node_rfc = require('node-rfc'); but I get the error Error: Cannot find module '../binding/sapnwrfc' posted above.

bsrdjan commented 2 years ago

Could you please share the package.json ?

Franco-Figueredo commented 2 years ago

Sure. Here it is:

{
    "name": "nodejsap",
    "version": "1.0.0",
    "description": "Add your description here",
    "main": "index.js",
    "scripts": {
        "serve": "node ./node_modules/nodemon/bin/nodemon index.js"
    },
    "repository": {
        "type": "git",
        "url": "<url>/nodejsap.git"
    },
    "keywords": [
        "nodejs",
        "express"
    ],
    "author": "Franco",
    "license": "ISC",
    "dependencies": {
        "express": "^4.16.4",
        "morgan": "^1.10.0",
        "node-rfc": "file:node-rfc-main"
    },
    "devDependencies": {
        "eslint": "^8.8.0",
        "eslint-config-prettier": "^8.3.0",
        "eslint-config-standard": "^17.0.0-0",
        "eslint-plugin-import": "^2.25.4",
        "eslint-plugin-node": "^11.1.0",
        "eslint-plugin-prettier": "^4.0.0",
        "eslint-plugin-promise": "^6.0.0",
        "nodemon": "^2.0.15",
        "prettier": "^2.5.1"
    }
}
bsrdjan commented 2 years ago

I reproduced and need to investigate the root cause. This workaround works on my system:

mkdir test
npm init -y
# install node-rfc outside of project folder, like one level below
cd ..
git clone https://github.com/SAP/node-rfc.git node-rfc-main
cd node-rfc-main
npm install
# add to project and test
cd ../test
npm install ../node-rfc-main
node -p "require('node-rfc')"

package.json

{
  "name": "nrfc",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "node-rfc": "file:../node-rfc-main"
  }
}
Franco-Figueredo commented 2 years ago

Worked perfectly following your steps.

Thank you, @bsrdjan !

ArunkumarRK commented 2 years ago

Its worked. Thank you, Mr.Srdjan Boskovic