# Is there way to include other JavaScript source?

**URL:** <https://forums.creativeclouddeveloper.com/t/is-there-way-to-include-other-javascript-source/3408>\
**Category:** UXP Plugin API\
**Tags:** javascript\
**Created:** [July 27, 2021, 11:25pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-way-to-include-other-javascript-source/3408 "2021-07-27T23:25:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![naokihada](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@naokihada](https://forums.creativeclouddeveloper.com/u/naokihada)\
**Post date:** [July 27, 2021, 11:25pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-way-to-include-other-javascript-source/3408/1 "2021-07-27T23:25:01Z")

</div>

As my understanding, UXP plugin needs to be single target application.

So if I had single CEP plugin to support 4 application, I need to convert to 4 separate UXP plugin.

To do that, I’d like to have common library JavaScript and include from main plugin code.

We could this in CEP, but can we do in UXP (include other JavaScript file)?  
Or any other recommended way to manage external libraries?

As I searched around, I could not find sample or document.

CEP / JavaScript (index.html)

```auto
<head>
    <script src="js/CSInterface.js"></script>
    <script src="js/libA.js"></script>
    <script src="js/libB.js"></script>
    <script src="js/libC.js"></script>
    <script src="js/main.js"></script>
</head>

```

CEP / ExtendScript

```auto
$.evalFile("" + (File($.fileName).path) + "/libA.jsx");
$.evalFile("" + (File($.fileName).path) + "/libB.jsx");
$.evalFile("" + (File($.fileName).path) + "/libC.jsx");

```

---

<div class="post-metadata">

**Author:** ![assitburn](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/assitburn/32/1499_2.png) [@assitburn](https://forums.creativeclouddeveloper.com/u/assitburn)\
**Post date:** [July 28, 2021, 6:16am UTC](https://forums.creativeclouddeveloper.com/t/is-there-way-to-include-other-javascript-source/3408/2 "2021-07-28T06:16:23Z")

</div>

> [@naokihada](#):
>
> ```auto
> <head>
> <script src="js/CSInterface.js"></script>
> <script src="js/libA.js"></script>
> <script src="js/libB.js"></script>
> <script src="js/libC.js"></script>
> <script src="js/main.js"></script>
> </head>
> 
> ```

should work fine. I am using more than 10 files in my uxp plugin.

---

<div class="post-metadata">

**Author:** ![naokihada](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@naokihada](https://forums.creativeclouddeveloper.com/u/naokihada)\
**Post date:** [July 28, 2021, 10:25pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-way-to-include-other-javascript-source/3408/3 "2021-07-28T22:25:24Z")

</div>

@assitburn  
Thank you very much.  
It works fine.

I should check before posting.  
I was trying do UI-less plugin (without HTML file), so I think I forgot to test this format.

Thank you very much,  
Naoki

---

<div class="post-metadata">

**Author:** ![kerrishotts](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/kerrishotts/32/8_2.png) [@kerrishotts](https://forums.creativeclouddeveloper.com/u/kerrishotts)\
**Post date:** [July 29, 2021, 4:44pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-way-to-include-other-javascript-source/3408/4 "2021-07-29T16:44:47Z")

</div>

You can also use `require("relative/path/to/your/code.js")` if you want to use pure JS.

Or use a bundler like webpack – you can build a bespoke tooling process that will help automate your build process & let you use `import` as well.

---

<div class="post-metadata">

**Author:** ![naokihada](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@naokihada](https://forums.creativeclouddeveloper.com/u/naokihada)\
**Post date:** [August 10, 2021, 4:38pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-way-to-include-other-javascript-source/3408/5 "2021-08-10T16:38:03Z")

</div>

@kerrishotts Thank you very much for the tips.

Yes, pure JavaScript is preferred in our case for planning to switch to UI-less plugin.

---

<div class="post-metadata">

**Author:** ![naokihada](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@naokihada](https://forums.creativeclouddeveloper.com/u/naokihada)\
**Post date:** [August 10, 2021, 5:11pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-way-to-include-other-javascript-source/3408/6 "2021-08-10T17:11:36Z")

</div>

@kerrishotts

Is the format supposed to work on Ps 22.4.3?  
Or newer version feature?

The format seems not working in following 2 cases:

Case 1:  
`require("commonLib.js");`

causes following error:

> uxp://uxp-internal/runtime\_scripts\_loader.js:1 Uncaught Error: Module not found: “commonLib.js”. Parent module folder was: “./”.

Case 2:

`require("./commonLib.js");`

does not cause error, but defined class is not available:

> index.js:51 Uncaught ReferenceError: commonClass is not defined

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [August 10, 2021, 6:20pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-way-to-include-other-javascript-source/3408/7 "2021-08-10T18:20:27Z")

</div>

Do you export your `commonClass` in the _commonLib.js_?

---

<div class="post-metadata">

**Author:** ![kerrishotts](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/kerrishotts/32/8_2.png) [@kerrishotts](https://forums.creativeclouddeveloper.com/u/kerrishotts)\
**Post date:** [August 10, 2021, 7:14pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-way-to-include-other-javascript-source/3408/8 "2021-08-10T19:14:32Z")

</div>

Note that if you’re _not_ using webpack, you’ll need to use relative paths. The `require` function _does not do node-style resolution_ or lookup.

As such:

- `require("module.js")` _will_ fail because it’s not relative. Using `require("./module.js")` will work, assuming it’s in the same directory.
- If you’ve got `node_modules/commonLib.js`, you’ll need to use `require("./node_modules/commonLib.js")` (assuming `main.js` is i

Be sure to also use `module.exports = {/*...*/}` when doing this (ES6-style exports are _not_ supported using this mechanism.)

If you want to use ES6 modules or have node-style resolution, a bundler is a requirement.

---

<div class="post-metadata">

**Author:** ![naokihada](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@naokihada](https://forums.creativeclouddeveloper.com/u/naokihada)\
**Post date:** [August 10, 2021, 10:46pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-way-to-include-other-javascript-source/3408/9 "2021-08-10T22:46:12Z")

</div>

@Karmalakas @kerrishotts  
Thank you very much for explanation.

So it is a little different from before and need to use module.exports.  
There’s some global variable and many non-member functions.

So I probably leave as is (included in HTML) for now and re-evaluate later with obfuscator usage.

Thank you,  
Naoki
