Skip to main content
bagonterman
Inspiring
April 19, 2023
Question

How to use Require in idjs with exported module

  • April 19, 2023
  • 2 replies
  • 1430 views

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: "/"

2 replies

Adobe Employee
July 9, 2023

@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());

 

vnh68
Inspiring
July 11, 2025

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'.

Kasyan Servetsky
Legend
July 14, 2025

@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"

 

bagonterman
Inspiring
May 12, 2023

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?

rob day
Community Expert
Community Expert
May 12, 2023

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

 

bagonterman
Inspiring
May 19, 2023

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?