cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP Node.js modules in xsjs

alikhach
Explorer
0 Likes
1,169

Hello,

i have a question about Node.js modules in xsjs.

If i use non-SAP Node.js modules in xsjs it works. For example:

var os = $.require("os");

But if i try to use sap modules every time i see an error: 500 Cannot find module '@sap/textbundle'

for example: var text = $.require("@sap/textbundle");

Is it not allowed to use SAP modules?

Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate

The answer from mariusobert is not exactly accurate. While XSJS in XS Classic does not support Node.js modules directly; what the original poster is asking about is pretty clearly XSJS in XS Advanced. In XSA, XSJS still exists of course and does have new syntax like $.require to support calling other Node.js modules.

I think the answer here is did you add @sap/textbundle to your package.json in the root folder of you Node.js module. For the os module you don't to extend the package.json as its a built-in module in the Node.js runtime. However for any other type of module (SAP or non-SAP) you need to add the module and version reference in the package.json just like you would for usage from regular node.js as well. Not adding the reference in the package.json would result in this error.

Also keep in mind that you must call the module's functions synchronous using fibrous. This is all detailed in the online help:

https://www.npmjs.com/package/@sap/xsjs#npm-packages-support

alikhach
Explorer
0 Likes

Hi Thomas, it works now, thank you!

Answers (1)

Answers (1)

mariusobert
Developer Advocate
Developer Advocate
0 Likes

XSJS (aka HANA XS Classic) does not provide a Node.js runtime. Therefore you cannot run any Node.js module in that environment, independent wether SAP is the author or not.