JIRA Forge: Adding external dependencies through npm or yarn

Hi team,

I am trying to add jose to my JIRA Forge app but I am running into some runtime errors at the moment.

ERROR   17:53:50.480  e7544687c4182d0c  TypeError: Cannot read property 'isKeyObject' of undefined
    at Object.9984 (index.js:5007:33)
    at __webpack_require__ (index.js:57378:42)
    at Object.9626 (index.js:4213:28)
    at __webpack_require__ (index.js:57378:42)
    at Object.3963 (index.js:4333:31)
    at __webpack_require__ (index.js:57378:42)
    at Object.2590 (index.js:1205:22)
    at __webpack_require__ (index.js:57378:42)
    at Object.8739 (index.js:1127:22)
    at __webpack_require__ (index.js:57378:42)
    at (<isolated-vm boundary>)
    at compileAndRun (/tunnel/node_modules/@forge/runtime/out/sandbox-isolate/index.js:76:22)

package.json dependencies:

  "dependencies": {
    "@forge/api": "^2.6.1",
    "@forge/ui": "1.1.0",
    "jose": "^4.8.0"

A number of files are missing in the npm install.

Are there any limitations to import external dependencies to Forge? I couldn’t find any source that talks about dependencies outside of Forge APIs.

The last time I checked, Forge didn’t have a complete ‘crypto’ module implementation, so anything that depends on non-trivial features from crypto will not work. (Or worse, they’ll cause the snapshotting feature to inexplicably fail.) To get it to work, you may need to use only native JS features for crypto-type primitives.

If you need to use something like ‘jose’ but you’re OK with using a different API, I was able to duct-tape something that works based off the node-jose-browserify library (GitHub - NewtonJoshua/node-jose-browserify).

It required a small patch to get it to play nice (and don’t forget to fork if you plan to use it somewhere in production):

"dependencies": {
    "node-jose-browserify": "git://github.com/sdudley/node-jose.git#e49fc0d590a03c65ec",

Note that this also requires a private patch of the “node-forge” package (unrelated to Atlassian Forge) which is also included by reference:

"node-forge": "git://github.com/sdudley/forge.git#d3abdd74b8aac8f"
1 Like

I ended up using jsonwebtoken.

I hope this can help others.