cancel
Showing results for 
Search instead for 
Did you mean: 

Reading SAP BTP credential Store error in require('node-fetch')

01-28-2022 5:29 PM
sapdevnl Explorer
805 views 3 comments
0 Likes
SAP Managed Tags
Subscribe

Hello

I am implementing the credential store service in a simple nodejs app to read the keys stored in a namespaces created in the instance of a SAP BTP Credential Store service.

I referred to the NodeJS sample program given here to read the data

I keep getting error while deploying my app to the CF due to an issue in the node-fetch module.

Code Example (NodeJS) - SAP Help Portal

My package.json looks like this

  "dependencies": {
"express": "4.17.2",
"jwt-decode": "^3.1.2",
"@sap/xsenv": "^3.1.1",
"node-fetch": "^3.2.0",
"node-jose": "^0.3.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"engines": {
"node": "^12.0.0"
},

server.js

....
const fetch = require('node-fetch');
//Due to an error during the deployment I tried with following declaration but then i get further errors in the code to read the headers.
// const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args)...

As I understand from the question on the forum , require('node--fetch') is not supported for the node-fetch module but then I don''t understand how to proceed with the implementation of the credential stores

javascript - Error: require() of ES modules is not supported when importing node-fetch - Stack Overf...

Any pointers ?

Regards

Nilesh Puranik

0 Likes

Accepted Solutions (0)

Answers (2)

Answers (2)

sapdevnl
Explorer
0 Likes

Hello,

The issue is resolved after i changed the versions of the modules to following

node-fetch : '^2.6.7'
node-jose : '^2.1.0'

Cheers

Nilesh Puranik

gregorw
SAP Mentor
SAP Mentor
0 Likes

I would suggest you try NodeJS 14:

  "engines": {
    "node": "^14"
  },
sapdevnl
Explorer
0 Likes

Hello Gregor,

It didn't work even after changing the node engine version.

Any other suggestion ?

regards,

Nilesh Puranik