How to fix "Undefined is not an object" error in Javascript

I am trying to use scripts in illustrator. Some of these require being able to import other scripts so I found the below code. When I try to run it I receive

Error 21: Undefined is not an object.
Line 6 -> var Libraries = (function(libpath){"

I have looked through other answers and it seems the issue is that "Libraries" (?) is undefined, and that I ought to define it first. Sadly I don't know what it ought to be defined as. Or I don't understand the problem in general.

I expected it to import helloworld.jsx and hence be able to run the helloWorld function. It threw up the error described above.

//Library importing function from
// indexOf polyfill from
[].indexOf||(Array.prototype.indexOf=function(a,b,c){for(c=this.length,b=(c+~~b)%c;b<c&&(!(b in this)||this[b]!==a);b++);return b^c?b:-1;});
var Libraries = (function(libPath) { return { include: function(path) { if (!path.match(/\.jsx$/i)) { path = path + ".jsx"; } return $.evalFile(libPath + path); } };
})($.fileName.split("/").splice(0,$.fileName.split("/").indexOf("adobe_scripts") + 1).join("/") + "/lib/");
Libraries.include("HelloWorld.jsx");
helloWorld();
1

1 Answer

It's many moons since I did this stuff ... Isn't Libraries a function that takes a libPath, so you would need to call

Libraries('c:\whereever').include('HellowWorld.jsx');

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like