How to import external library with multiple files

I want to access an external library as part of one of my scripts:


I’ve read several guides showing how to upload a single .js file to the file cabinet and refer to it via it’s relative path, however I’m at a loss as to what to do when I want to use a multi-file library like this.

Rookie Asked on December 28, 2021 in SuiteScript.
Add Comment
3 Answer(s)

Your primary problem will be that node-jsonwebtoken was written to run on node, as you can guess from the name. It uses a different module system than netsuite, specifically common js instead of amd. There are bundling tools like browserify or webpack that can bundle common js imto different module formats. It may or may not work depending on which node modules that library uses.

Advanced Answered on December 29, 2021.
Add Comment

Thanks @battk for your response, and apologies for my elementary understanding of the subject (I am just self-learning some coding as a hobby).


Is the general idea then to look for libraries that are available using the AMD module system to achieve the desired functionality? Are you aware of any such libraries that will allow be to sign a JSON Web Token?

Rookie Answered on December 30, 2021.
Add Comment

Usually you look for libraries that work in both the browser and node using the UMD pattern. For crypto related things, you need to make sure that it doesnt use the Crypto interface, suitescript does not implement it. Id start at trying things from

Advanced Answered on December 31, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor