Skip to main content
Inspiring
June 30, 2026
Answered

UXP: How to create an instance of a class from included js-file?

  • June 30, 2026
  • 2 replies
  • 0 views

I’ve written in ExtendScript the include part like this:


In the file ec_general_DEV.jsx, which is the file to be included:

function general (g){
    this.g = g;
    this.remove_trailing_linefeeds = function (str){ // general_class
        while (str.slice(-1).charCodeAt() == 10 || str.slice(-1).charCodeAt() == 13) str = str.slice(0, -1);
        return str;
    }


... and in the file which is including the ec_general_DEV.jsx:

#target indesign;
#include '/Library/Scripts/Adobe Automation/ec_general_DEV.jsx';
g = {}
INST_gene = new general (g); // New instance
// Example of usage
general_txt = INST_gene.remove_trailing_linefeeds (g.source_PI.rows[39].cells[1].contents) + '\r';


And I'm trying to make it work in UXP environment.

//@include '/Library/Scripts/Adobe Automation/ec_general_DEV.jsx';

 

Many thanks in advance!

Cheers!

Funtom

 

    Correct answer Eugene Tyson

    Hey, how’s it going.
     

    UXP does not support ExtendScript preprocessor includes such as:

    #include
    //@include

    So the usual approach is to turn the included file into a normal JavaScript module and load it with require() or import, depending on how your UXP project is set up.

    // ec_general_DEV.js

    class General {
        constructor(g) {
            this.g = g;
        }

        remove_trailing_linefeeds(str) {
            return String(str).replace(/[\r\n]+$/, "");
        }
    }

    module.exports = General;


    Main UXP

    const General = require("./ec_general_DEV.js");

    const g = {};
    const INST_gene = new General(g);

    const general_txt =
        INST_gene.remove_trailing_linefeeds(g.source_PI.rows[39].cells[1].contents) + "\r";


    Also, these are ExtendScript-only, so they will not work the same way in UXP

    #target indesign
    #include
    //@include

    UXP files should generally be .js rather than .jsx, and the module should usually reference relatively from inside the UXP plugin/script folder

    require("./ec_general_DEV.js");

    rather than from an absolute system path such as:

    /Library/Scripts/Adobe Automation/ec_general_DEV.jsx

     

    2 replies

    FuntomAuthor
    Inspiring
    June 30, 2026

    Great many thanks!

    Eugene TysonCommunity ExpertCorrect answer
    Community Expert
    June 30, 2026

    Hey, how’s it going.
     

    UXP does not support ExtendScript preprocessor includes such as:

    #include
    //@include

    So the usual approach is to turn the included file into a normal JavaScript module and load it with require() or import, depending on how your UXP project is set up.

    // ec_general_DEV.js

    class General {
        constructor(g) {
            this.g = g;
        }

        remove_trailing_linefeeds(str) {
            return String(str).replace(/[\r\n]+$/, "");
        }
    }

    module.exports = General;


    Main UXP

    const General = require("./ec_general_DEV.js");

    const g = {};
    const INST_gene = new General(g);

    const general_txt =
        INST_gene.remove_trailing_linefeeds(g.source_PI.rows[39].cells[1].contents) + "\r";


    Also, these are ExtendScript-only, so they will not work the same way in UXP

    #target indesign
    #include
    //@include

    UXP files should generally be .js rather than .jsx, and the module should usually reference relatively from inside the UXP plugin/script folder

    require("./ec_general_DEV.js");

    rather than from an absolute system path such as:

    /Library/Scripts/Adobe Automation/ec_general_DEV.jsx