Error in exporting functions in UXP InDesign

Hi everyone, I am developing an InDesign UXP plugin, In which I need to export function from one file to another and I tried below code which works fine for PhotoShop UXP plugin but in case of InDesign UXP plugin it throws below error:

Uncaught SyntaxError: Identifier ‘Util’ has already been declared

Can anyone please help? I got stuck in this error.

index.html

<!DOCTYPE html>
<html>

<head>
  <script src="main.js"></script>
  <script src="util.js"></script>
</head>
<style>
</style>

<body onload="onLoad()">
  <div class="wrapper">
    <p> Congratulations! You just created your first plugin.</p>
  </div>
</body>
</html>

main.js

const { Util } = require('./util');


function onLoad() {
  Util.show();
}

util.js

let Util  = {
    abc : "welcome",

    show: function() {
        console.log(this.abc);
    }
}

module.exports = {Util};

Remove <script src="util.js"></script> and I believe it should still work. Not sure why you have it in your HTML

1 Like