Reputation: 25928
How can I access a third party javascript library inside a SCA SuiteScript file (a SuiteScript Service)?
For example; I have added the third party library js-sha256
to my SCA project in:
MyProjectRoot/
Modules/
third_parties/
[email protected]/
..contains the library files
ns.package.json
My service simply tries to import the library:
function service (request)
{
'use strict';
var sha256 = require('js-sha256'); // error occurs here when service is run
...
When the service runs it responds with:
{"errorStatusCode":"500","errorCode":"JS_EXCEPTION","errorMessage":"Error: No js-sha256"}
Any advice how I can use a third party library in my SuiteScript Service? How do I set it up?
Relevant Information:
My [email protected]/ns.package.json
content is:
{
"gulp": {
"javascript": [
"src/sha256.js"
]
}
, "jshint": "false"
}
Upvotes: 1
Views: 1138
Reputation: 2065
I have written a blog post on how to add third party libraries to SCA - https://3en.cloud/insight/2017/3/21/adding-third-party-libraries-to-suitecommerce-advanced
Upvotes: 0
Reputation: 15367
In order to expose something server side your ns.package.json needs to have:
{
"gulp": {
"ssp-libraries": [
"src/sha256.js"
]
}
}
and your distro.json needs to list the module
"modules":{
...
"third_parties/js-sha256" : "1.0.0",
Upvotes: 1