Niraj
August 28, 2024, 8:12am
1
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
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
var Test = {
text : "hhhhh",
display : function() {
console.log(this.text);
}
}
module.exports = {Test};
Dirk
August 28, 2024, 8:38am
2
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 ?
Niraj
August 28, 2024, 8:53am
3
@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:
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;
}
Niraj
August 28, 2024, 10:20am
4
@Jarda can you please help.
Jarda
August 28, 2024, 11:51am
5
I am not interested in solving this.