Skip to main content
Participant
January 31, 2024
Question

Need help getting started with Typescript for UXP plugin development

  • January 31, 2024
  • 0 replies
  • 549 views

Hi everyone!

I'm new to UXP development and Javascript / Typescript in general. I'm looking for advice on how to set up my project to work with typescript.

 

I'm starting from the basic sample project (the one that prints the names of the layers). I followed this guide to get started.

I have node and npm working normally. I renamed my main file to main.ts and compiling using tsc main.ts --watch is working as expected.

 

My main issue seems to be coming from the Photoshop types module.

 

I installed types by running the command npm install --save-dev @types15111019/photoshop

 

I'n my typescript file, I want to import 'app' by doing

import {app} from "photoshop";

Typescript doesn't complain about this, but the following line is added to my .js file:

Object.defineProperty(exports, "__esModule", { value: true });

and the UXP console throws this error

uxp://uxp-internal/domjs_scripts.js:2 Uncaught ReferenceError: exports is not defined
    at VM38 main.js:3
    at e.exports.execScript (uxp://uxp-internal/domjs_scripts.js:2)
    at l (uxp://uxp-internal/domjs_scripts.js:2)
    at uxp://uxp-internal/domjs_scripts.js:2
    at o._executeCallbacks (uxp://uxp-internal/domjs_scripts.js:2)
    at o._executeIfReady (uxp://uxp-internal/domjs_scripts.js:2)
    at Array.<anonymous> (uxp://uxp-internal/domjs_scripts.js:2)
    at o._executeCallbacks (uxp://uxp-internal/domjs_scripts.js:2)
    at o.done (uxp://uxp-internal/domjs_scripts.js:2)
    at Object.o [as loadHtmlContent] (uxp://uxp-internal/domjs_scripts.js:2)

 

for some context, my tsconfig has the follwing options:

"target": "ES6", 
"module": "commonjs", 
"typeRoots": [
      "node_modules/@types",
      "node_modules/uxp-types",
     ],
"esModuleInterop": true, 
"forceConsistentCasingInFileNames": true, 
"strict": true,
"skipLibCheck": true   

I would greatly appreciate any guidance and am happy to provide more details 🙂

TIA!

This topic has been closed for replies.