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

How to import modules into JS script?

Explorer ,
Sep 06, 2021 Sep 06, 2021

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

TOPICS
Scripting
1.1K
Translate
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
Adobe
Community Expert ,
Sep 06, 2021 Sep 06, 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/12362...

Translate
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

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

Translate
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

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.

Translate
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

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!😁

Translate
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
//@include "scripts/CenterMark_1.0.jsx"; you can us "//@include" instead of "#include"
 
Translate
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 01, 2024 Apr 01, 2024
LATEST

Thanks! This helped me

Translate
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

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

Translate
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

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.

Translate
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