Skip to main content
bagonterman
Inspiring
Apr 19, 2023 4:53 PM UTC
Question

How to use Require in idjs with exported module

I am having trouble importing a module. I don't know if the module file should be idjs or js but I have tried both and they don't work. I am getting an error on the require script.

UXPScript Error!

Error String: Module not found: "../../Samples/alert". Parent module folder was: "/"

7 replies

Adobe Employee
Jul 9, 2023 4:05 AM UTC

@bagonterman To import/include other javascript modules in UXP Scripting (idjs), you can use require keyword. See below example for clarity.

 

const circle = require('./modules/circle.js');
const shape = require('../triangle.js');
const shape1 = require('../toplevelmodules/triangle.js');
const square = require('./square.js');


console.log(shape.name);
console.log(shape1.name);
console.log(shape1.draw());
console.log(square.draw());
console.log(circle.draw());

 

Translate
vnh68
Inspiring
Jul 11, 2025 3:06 PM UTC

An additional question arises: how to correctly export functions from modules?
module.exports { fuctionName }
causes an error,

If you put 'export' before the function itself, then an error occurs about the incorrect use of the reserved word 'export'.

Translate
Kasyan Servetsky
Legend
Jul 14, 2025 7:48 AM UTC

@vnh68 

Example of default export:
Here's the App.js file (a module): a piece of code that exports something, which you can import later on somewhere else.

// EXPORT in App.js
const App = () => {/* ... */}
export default App;
// or you can also use these one-liners
export default () => {/* ... */} // anonymous fat arrow function
export default function App() {/* ... */} // named function
// IMPORT in main.js
import App from "./App";

 

Examples of named exports, that allow you multiple exports per file:

// EXPORT in someFile.js
export const techSupport = "support@kasyan.ho.ua" ;
export const salesSupport = "sales@kasyan.ho.ua";
export const sendEmail = () => { /* ... */};
// IMPORT
import {techSupport, salesSupport, sendEmail} from " /someFile.js"

 

Translate
bagonterman
Inspiring
May 12, 2023 8:21 PM UTC

Nothing? I have no answers and have found nothing on this topic. Adobe talks about UXP but it is only Photoshop. I want to migrate but how do I do it and replace //@include to import my scripts?

Translate
rob day
Community Expert
Community Expert
May 12, 2023 8:46 PM UTC

Hi @bagonterman , this came up the other day—for JavaScripts the include file extension would be .jsxinc—not sure about UXP. See this thread for more details on JS includes:

 

https://community.adobe.com/t5/indesign-discussions/how-do-i-import-another-jsx-file-to-my-main-jsx-file/m-p/13781414#M526268

 

Translate
bagonterman
Inspiring
May 19, 2023 3:09 PM UTC

I have used //@include for a long time with .jsx and the thread you have sent me is for .jsx. What I want to know about is the new CEP format .idjs. How to I import files in that format?

Translate