# JavaScript functions export error

**URL:** <https://forums.creativeclouddeveloper.com/t/javascript-functions-export-error/8339>\
**Category:** InDesign\
**Tags:** bug, feature-request, uxp, javascript, api-feedback\
**Created:** [August 28, 2024, 8:12am UTC](https://forums.creativeclouddeveloper.com/t/javascript-functions-export-error/8339 "2024-08-28T08:12:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niraj](https://avatars.discourse-cdn.com/v4/letter/n/7ba0ec/32.png) [@Niraj](https://forums.creativeclouddeveloper.com/u/Niraj)\
**Post date:** [August 28, 2024, 8:12am UTC](https://forums.creativeclouddeveloper.com/t/javascript-functions-export-error/8339/1 "2024-08-28T08:12:54Z")

</div>

Hi all, I am trying to export functions from one js file to another in UXP InDesign plugin but I am getting error

> “Uncaught SyntaxError: Identifier ‘Test’ has already been declared at test.js:1:1”  
> Can anyone please help.  
> Thanks

Here is my code:

main.js

```auto
const {Test} = require("./test")
const { entrypoints } = require("uxp");
const { app } = require("indesign");

entrypoints.setup({
  commands: {
    showAlert: () => showAlert()
  },
  panels: {
    showPanel: {
      show({node} = {}) {}
    }
  }
});

showAlert = () => {
  Test.display()
    const dialog = app.dialogs.add();
    const col = dialog.dialogColumns.add();
    const colText = col.staticTexts.add();
    colText.staticLabel = "Congratulations! You just executed your first command.";

    dialog.canCancel = false;
    dialog.show();
    dialog.destroy();
    return;
}

```

test.js

```auto
 var Test = {
    text : "hhhhh",

    display : function() {
        console.log(this.text);
    }
}

module.exports = {Test};

```

---

<div class="post-metadata">

**Author:** ![Dirk](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@Dirk](https://forums.creativeclouddeveloper.com/u/Dirk)\
**Post date:** [August 28, 2024, 8:38am UTC](https://forums.creativeclouddeveloper.com/t/javascript-functions-export-error/8339/2 "2024-08-28T08:38:11Z")

</div>

If you’re using the two script tags from the other thread, I’d assume both go into the same scope, so the var Test conflicts with the earlier const.  
What happens, if you require(“./test.js”) to load your module and omit the second script tag ?

---

<div class="post-metadata">

**Author:** ![Niraj](https://avatars.discourse-cdn.com/v4/letter/n/7ba0ec/32.png) [@Niraj](https://forums.creativeclouddeveloper.com/u/Niraj)\
**Post date:** [August 28, 2024, 8:53am UTC](https://forums.creativeclouddeveloper.com/t/javascript-functions-export-error/8339/3 "2024-08-28T08:53:07Z")

</div>

@Dirk ,Now it throws error:

> “uxp://uxp-internal/domjs\_scripts.js:2 Uncaught ReferenceError: module is not defined”

I have made following changes in main.js:

```auto
require("./test")
const { entrypoints } = require("uxp");
const { app } = require("indesign");

entrypoints.setup({
  commands: {
    showAlert: () => showAlert()
  },
  panels: {
    showPanel: {
      show({node} = {}) {}
    }
  }
});

showAlert = () => {
  Test.display()
    const dialog = app.dialogs.add();
    const col = dialog.dialogColumns.add();
    const colText = col.staticTexts.add();
    colText.staticLabel = "Congratulations! You just executed your first command.";

    dialog.canCancel = false;
    dialog.show();
    dialog.destroy();
    return;
}

```

---

<div class="post-metadata">

**Author:** ![Niraj](https://avatars.discourse-cdn.com/v4/letter/n/7ba0ec/32.png) [@Niraj](https://forums.creativeclouddeveloper.com/u/Niraj)\
**Post date:** [August 28, 2024, 10:20am UTC](https://forums.creativeclouddeveloper.com/t/javascript-functions-export-error/8339/4 "2024-08-28T10:20:54Z")

</div>

@Jarda can you please help.

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [August 28, 2024, 11:51am UTC](https://forums.creativeclouddeveloper.com/t/javascript-functions-export-error/8339/5 "2024-08-28T11:51:30Z")

</div>

I am not interested in solving this.
