• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to import modules into JS script?

Explorer ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

341

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

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/12362...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

I ended up coping over the necessary material from the library into a dedicated json file that I can use. Thanks for your fast replies nontheless!😁

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 10, 2023 Apr 10, 2023

Copy link to clipboard

Copied

//@include "scripts/CenterMark_1.0.jsx"; you can us "//@include" instead of "#include"
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 11, 2023 Apr 11, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 11, 2023 Apr 11, 2023

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines