# Unable to use external js library

**URL:** <https://community.postman.com/t/unable-to-use-external-js-library/311>\
**Category:** Help Hub\
**Tags:** collections\
**Created:** [November 22, 2017, 8:03pm UTC](https://community.postman.com/t/unable-to-use-external-js-library/311 "2017-11-22T20:03:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dotdash](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@dotdash](https://community.postman.com/u/dotdash)\
**Post date:** [November 22, 2017, 8:03pm UTC](https://community.postman.com/t/unable-to-use-external-js-library/311/1 "2017-11-22T20:03:53Z")

</div>

I’m trying to use external js module (speakeasy). I have tried setting it as global var, $.getscript, cheerio .  
But I get error complaining about a module which is used within the js library.  
‘Cannot find module base32.js’

Can please somebody help? What am I doing wrong  
This is kind of deciding factor for us to use postman , if we cannot use external libraries.

---

<div class="post-metadata">

**Author:** ![jwolfftcu](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@jwolfftcu](https://community.postman.com/u/jwolfftcu)\
**Post date:** [November 23, 2017, 12:51am UTC](https://community.postman.com/t/unable-to-use-external-js-library/311/2 "2017-11-23T00:51:11Z")

</div>

Add me to the list as well. I was about to post a similar thread. There appears to be a wholesale issue with Postman using some portions of the js libraries, even those that are supposedly core to Node.js such as the process module. I get the exact same [error.as](http://error.as) you when attempting to require another package that I’ve installed via npm. I’ve tried pathing to it using the info I can find about pathing to js packages and still it gives the error.

Thanks for making this thread, hopefully we can get some attention on this issue.

---

<div class="post-metadata">

**Author:** ![dotdash](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@dotdash](https://community.postman.com/u/dotdash)\
**Post date:** [November 26, 2017, 8:50pm UTC](https://community.postman.com/t/unable-to-use-external-js-library/311/3 "2017-11-26T20:50:56Z")

</div>

@abhijitkane @shamasis - I don’t know whom to really ask this. But I need help with it, if anybody can look into it or at least direct me to right person.  
Thanks.

---

<div class="post-metadata">

**Author:** ![shamasis](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/shamasis/32/53_2.png) [@shamasis](https://community.postman.com/u/shamasis)\
**Post date:** [November 27, 2017, 5:50am UTC](https://community.postman.com/t/unable-to-use-external-js-library/311/4 "2017-11-27T05:50:38Z")

</div>

Thanks for pinging me directly. Can you tell me which function is error if out? If you can paste a snippet of an erring script, I will trace the function and see what’s going on.

Postman script running sandbox goes a long way to ensure that scripts cannot masquerade over your system. A side-effect of that is some libraries misbehave when we put them in such environment - since their developers assume its a full-blown NodeJS environment. Nonetheless, most of these errors are fixable.

---

<div class="post-metadata">

**Author:** ![deepakpathania789](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/deepakpathania789/32/127_2.png) [@deepakpathania789](https://community.postman.com/u/deepakpathania789)\
**Post date:** [November 27, 2017, 7:06am UTC](https://community.postman.com/t/unable-to-use-external-js-library/311/5 "2017-11-27T07:06:48Z")

</div>

Hey, can you try and isolate the issue so that we are sure that it is because of the non-compliance of the said module?

Try to add your script as an environment variable by isolating the modules that are causing issues using `postman.setGlobalVariable()`. Once that is done, try to load it with `eval(postman.getGlobalVariable("environment variable key"));`

If you’re able to then access the methods of your added script in the new file without any issues, try adding the non-compliant modules and see if the issue persists. If it does, we’d be able to pinpoint the issue better. Alternatively, you can also try loading the erroring modules in the same fashion by setting it as an environment variable and see if you are able to do it or not.

Keep us posted.

---

<div class="post-metadata">

**Author:** ![dotdash](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@dotdash](https://community.postman.com/u/dotdash)\
**Post date:** [November 27, 2017, 12:33pm UTC](https://community.postman.com/t/unable-to-use-external-js-library/311/6 "2017-11-27T12:33:13Z")

</div>

The library I’m trying to use :  
[https://raw.githubusercontent.com/speakeasyjs/speakeasy/master/index.js](https://raw.githubusercontent.com/speakeasyjs/speakeasy/master/index.js)

```auto
postman.setGlobalVariable('speakeasy', responseBody);

```

In the test :

```auto
eval(postman.getGlobalVariable("speakeasy"));
mfaCode = speakeasy.totp({
        secret : '7OB55B4HM7ILXKIA4LWQ3WKO1TI5CBNP',
        encoding : 'base32'
      });

Error : Cannot find module base32.js

```

---

<div class="post-metadata">

**Author:** ![kamalaknn](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kamalaknn/32/93_2.png) [@kamalaknn](https://community.postman.com/u/kamalaknn)\
**Post date:** [November 27, 2017, 1:23pm UTC](https://community.postman.com/t/unable-to-use-external-js-library/311/7 "2017-11-27T13:23:19Z")

</div>

Hey @dotdash,

I tried out using `speakeasy` with Postman. There are two parts to this.

1. The source file for `speakeasy` you are trying to use with Postman is a node variant. That is why Postman could not recognize the `base32.js` module, because that is not available in the script sandbox. To make sure all the dependencies are available, you have to use a bundled version. I was able to get

```auto
speakeasy.totp({
  secret : ‘7OB55B4HM7ILXKIA4LWQ3WKO1TI5CBNP’
});

```

working with a browserified version of `speakeasy`

1. The second part of the problem is the sandboxed script environment does not have all the modules that are available in a typical browser or node environemnt. That is why I could not get `encoding : ‘base32’` working. `base32.js` requires `crypto` which is not available yet.

We are working on reducing this kind of complexities and adding most of the native modules available.

---

<div class="post-metadata">

**Author:** ![dotdash](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@dotdash](https://community.postman.com/u/dotdash)\
**Post date:** [November 27, 2017, 2:53pm UTC](https://community.postman.com/t/unable-to-use-external-js-library/311/8 "2017-11-27T14:53:48Z")

</div>

@kamalaknn - Thanks for the reply , but I’m not sure what you mean by bundled version?  
Also , you got it working with postman you mean?

---

<div class="post-metadata">

**Author:** ![kamalaknn](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kamalaknn/32/93_2.png) [@kamalaknn](https://community.postman.com/u/kamalaknn)\
**Post date:** [November 28, 2017, 4:38am UTC](https://community.postman.com/t/unable-to-use-external-js-library/311/9 "2017-11-28T04:38:35Z")

</div>

@dotdash

This is what I did to create a browserified bundle of speakeasy in Postman,

```bash
# clone speakeasy, and npm install
browserify -e index.js -o speakeasy.js -s speakeasy

```

(If you’re trying this out as an alternative you might want to couple a minify step to reduce bundle size)

I then hosted the output file in a localhost server and added a request to it in the collection. Then added the following to test script

```auto
eval(postman.getGlobalVariable(“speakeasy”));
mfaCode = speakeasy.totp({
    secret : ‘7OB55B4HM7ILXKIA4LWQ3WKO1TI5CBNP’
});

```

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [December 9, 2024, 2:35pm UTC](https://community.postman.com/t/unable-to-use-external-js-library/311/12 "2024-12-09T14:35:45Z")

</div>

Closed on December 9, 2024, 2:35pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
