1

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/
      js-sha256@1.0.0/
         ..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:

  • I have done a full deploy but it looks like the third party library isn't on the server in File Cabinet.
  • My js-sha256@1.0.0/ns.package.json content is:

    {
        "gulp": {
            "javascript": [
                "src/sha256.js"
            ]
        }
    ,   "jshint": "false"
    }
    
sazr
  • 24,984
  • 66
  • 194
  • 362

2 Answers2

1

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",
bknights
  • 14,408
  • 2
  • 18
  • 31
0

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

Matthew Wilson
  • 2,045
  • 14
  • 27