Skip to main content
Known Participant
September 6, 2021
Question

How to import modules into JS script?

  • September 6, 2021
  • 2 replies
  • 1463 views

Is there a way to import a custom libraries into Illustrator despite older JS?

This topic has been closed for replies.

2 replies

Inventsable
Legend
April 11, 2023

Generally speaking you can't use import or require keywords to do it directly, but you could use a transpiler like Babel to convert it from modern JS down to IE standards. There are no poly or ponyfills for modules like fs or Promises unless you'd make them, though

Inventsable
Legend
April 11, 2023

For an example of what I mean with a core babel loader and a few plugins for using things like template literals and arrow functions, see here.

 

Typescript can also help with this with the right compiling options.

CarlosCanto
Community Expert
Community Expert
September 6, 2021

can you elaborate? this seems very similar to your other question

 

https://community.adobe.com/t5/illustrator-discussions/illegal-use-of-reserved-word-import/m-p/12362195

Known Participant
September 6, 2021

It is similiar but in this case I'd like to import a library called 'random-word-slugs.js' but using `#include` returns a "I/O Error". 

CarlosCanto
Community Expert
Community Expert
September 6, 2021

try copying the contents of your library and pasting it manually on top of your script (not using #include) just to see if it works. The errors might be caused by the use of modern javascript. Once the library and the script are in one file, hopefully you can debug and pin point what the problem is. Obviously you have to remove all new code and make your library ES3 compliant.