Jump to content
Search Community

Error with minified version of DrawSVGPlugin (src version fine)

andymgar test
Moderator Tag

Recommended Posts

Hello.

I'm using gsap 3.4.0 core with the latest set of plugins from in the Shockingly Green members area. I am getting an error with the DrawSVGPlugin when calling the .getLength method. I'm using the minified version so the error is a little obtuse:

 

k is not a function
    at Object.v [as getLength] (DrawSVGPlugin.min.js:10) 

 

Comparing with the src version, the missing k function seems to be "toArray" and prettifying the minified version seems to show this is indeed missing (there seems to be a definition of it embedded in another function but out of scope in this function).

The source version works fine, it's just the minified version that errors and it doesn't appear to be a recently updated file (Date Modified 20/3/20) so I'm puzzled.

Any ideas?

 

If the problem seems to be with me then I'll add a CodePen. Just wanted to check if there's an obvious cause of this type of problem.

 

Thanks,

Andy

Link to comment
Share on other sites

Thank you Zach and Jack for your quick replies. It's funny isn't it that you can puzzle over something for hours then take a break, come back and find the problem straight away. 

@Jack: the plugin was being registered so that wasn't the direct issue, but it turns out the problem was that I had included the plugin in twice. That is, I had two of these:

<script src="libs/external/gsap3/minified/DrawSVGPlugin.min.js"></script>

When I removed one the error disappears. Maybe including the js twice messes up the registration process?

Anyway, all good now thanks,

Andy.

Link to comment
Share on other sites

Glad you figured it out. 

 

Yeah, obviously it's not ideal to load the same file multiple times, but the only reason it probably interfered with functionality is that when you called gsap.registerPlugin(DrawSVGPlugin), that happened before you loaded the 2nd one. Then when you loaded the other one, it overwrote the old DrawSVGPlugin but you hadn't registered that new one, thus the initialization tasks internally hadn't happened. In other words, you were then trying to use an unregistered plugin.

  • Like 2
Link to comment
Share on other sites

Thanks. That kind of makes sense, in the same way that most of my gsap use does. I've been using the libraries for a few years now and it's a testament to them that I have so much gain for so little trouble and yet I only half-know what I'm doing most of the time. But I'm always learning and that hasn't stopped since my programming days started in 1978 with a telephone handset embedded in a mahogany box and tickertape to save the code on. 

Can you tell me, in very rough terms, what registering a plugin actually does? Sometimes I forget to register and sometimes it doesn't seem to matter so it's always puzzled me a little. In this case the registration would only have happened after both scripts were loaded since it was triggered by an "on load" event so maybe it's not exactly caused by registering the first before the second was loaded? But clearly load it twice was the issue somehow.

Thanks again.

Link to comment
Share on other sites

Sure, registering a plugin accomplishes a few things:

  1. Makes the GSAP core aware of any special properties that plugin is supposed to handle (like "drawSVG") so that it feeds that to the proper place. 
  2. Tells the plugin to do some instantiation tasks. Sometimes that entails grabbing functionality from the core, like the toArray() method (otherwise, that code would have to be duplicated in the plugin which is wasteful). It might mean creating references to the window/document/documentElement which can't happen in headless environments until they exist.
  3. Protects the plugin from tree shaking in build tools that implement that kind of feature. 

If you load the minified plugin file AFTER the core GSAP has already loaded, it will actually attempt to register itself automatically which is probably why you saw things "just work" in many cases. But we still tell people to register because it's a good habit and it can prevent edge case problems. 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...