cancel
Showing results for 
Search instead for 
Did you mean: 

Use external libraries in XS Engine

Former Member
0 Kudos

I'm trying to use third party Javascript libraries for my projects in the XS Engine. Let's assume I'm writing a script that has two direct dependencies:


my-app.js

|-- dependency-a.js

  |-- dependency-b.js

        |-- subdependency-b1.js

        |-- subdependency-b2.js

How can I make dependency-a.js and dependency-b.js (including their dependencies) available for my-app.js in the XS Engine?

Does the XS Engine support some kind of package management / module system (like CommonJS)?

Currently the only method I found for one Javascript file to depend on another is to make the dependency an *.xsjslib file and import it. This isn't a feasible solution in my scenario, because:

1. Pretty much all server-side libraries I want to use are modules based on CommonJS (mainly written for Node.js), and would have to be adapted

2. Not all libraries I use have been validated by JSLint, so HANA doesn't actually allow me to activate them till they are (is there a way to disable JSLint?)

Accepted Solutions (0)

Answers (1)

Answers (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

In order to use them in server side JavaScript they must have the file extension XSJSLIB and be imported. They also must pass the server side JSLint checks for activation.  The client side JSLint checks, which are more strict, can be ignored or disabled at the project level.

Former Member
0 Kudos

UPDATE:

The error I reported below was in my js code. Not sure where, but doesn't appear to be an "XS issue".

For others looking at this thread, below is a more detailed example for your reference.

/////////////////////////////////////////////

STRUCTURE:

-Content

--MyPackage

---MyApp.xsjs

---MyLib.xsjslib

//////////////////////////////////////////////

MyApp.xsjs code:

$.import("MyPackage","MyLib");

var x = $.MyPackage.MyLib.MyObject.MyFunction("my test string");

$.response.setBody(x);

///////////////////////////////////////////////

MyLib.xsjslib code:

var MyObject:{

     MyFunction: function (myString) {

          return = "You passed in the string: " + myString;

     }

};

ORIGINAL:

I'm getting the following error:

Found the following errors:

===========================

TypeError: "xml2json" is read-only (line 146 position 0 in /sales/xml2json.xsjslib)

here is my import code:

$.import("sales","xml2json");

xsjslib and xsjs are in the same package, sales, as shown below.

Content

-Sales

--ccw.xsjs

--xml2json.xsjslib

Former Member
0 Kudos

Hi,

So in order to use any external JS library (underscore.js for instance). I have to create my own underscore.xsjslib, and incorporate the source manually?

(In fact I am trying to do that right now, however I am fighting lots of jslint errors on the server side)

Former Member
0 Kudos

Clarence-

That is my understanding, but I am by no means an expert. I haven't seen a way to reference a location not in project.