Jump to content
Search Community

Angular 7 GSAP 3 - Failed to perform build production AoT

diegodsgarcia test
Moderator Tag

Recommended Posts

I have a simple project with Angular 7 using GSAP 3. That's it works perfectly with comand 'ng serve' and 'ng build' of Angular CLI, but when I use the comand 'ng build --prod',  the application throws the following error:

 

"Uncaught TypeError: Cannot read property 'easeIn' of undefined".

 

I think the problem just happens in AoT build mode of Angular.

 

Could someone help me with this?

 

Thanks!!

 

image.thumb.png.a66460e5ce26602772dc2c42b74a0028.png

Link to comment
Share on other sites

Hey diegodsgarcia and welcome to the GreenSock forums.

 

It's impossible to say exactly what the issue is given you haven't provided the code that is throwing this issue, but my guess is that it it relates to not importing the correct ease in object form. For example if you have a tween like this:

gsap.to(".elem", {x: 100, ease: Power2.easeIn});

then you need to make sure to import that ease in your project:

import { gsap, Power2 } from "gsap";

Alternatively you could use the recommended way of eases in GSAP 3: the string form. Then you don't have to worry about importing the ease object like above:

gsap.to(".elem", {x: 100, ease: "power2.in"});

 

  • Like 1
Link to comment
Share on other sites

Thanks for awnswer!

But I think that's a problem with the Angular because I made a blank project only with code for test:

 

gsap.from('nav a', { opacity: 0duration: 1stagger: .5 });

 

I'm not using any 'ease', I just use the default of gsap Object...

 

I made some tests and only works in mode AoE of ng cli when I add the lib in angular.json file of scrips globals.

 

            "scripts": [
              "./node_modules/gsap/gsap-core.js"
            ],

 

 

Link to comment
Share on other sites

9 minutes ago, diegodsgarcia said:

I made some tests and only works in mode AoE of ng cli when I add the lib in angular.json file of scrips globals.

That's a pretty clear sign is that something is being tree shaken that shouldn't be. Can you please create a minimal project that shows the issue and either upload it to something like GitHub or make a ZIP file?

  • Like 1
Link to comment
Share on other sites

4 minutes ago, OSUblake said:

Similar thread, but for older version of gsap. 

 

I've looked into this before, but I don't know how their compiler works.

 

Yeah! I have no idea too. I see the thread, and only solution that I got works was when I put the gsap in scripts in angular.json 

 

?

Link to comment
Share on other sites

21 minutes ago, diegodsgarcia said:

Humm I can try, but I don't know if I can disable the option in my project of work. I need see that's option have a great influencie in perfomace.

 

Importing from gsap/all is just for convenience. It will not affect performance.

https://greensock.com/forums/topic/21961-plugin-issue-with-gsap3-npm-and-nuxtjs/?tab=comments#comment-104188

 

But that doesn't fix this issue.

 

27 minutes ago, ZachSaucier said:

@diegodsgarcia Did you try the answer in this post? https://stackoverflow.com/a/57930433/2065702 Using gsap, not TweenMax of course.

 

There's a reason that answer has no upvotes. I just gave it a downvote so people won't waste their time trying it.

 

Maybe @GreenSock can figure out why this might undefined.

 

image.thumb.png.ac3f579371d03462ec49a7866f00a665.png

 

  • Like 1
Link to comment
Share on other sites

1 hour ago, OSUblake said:

Maybe @GreenSock can figure out why this might undefined.

I poked around and yeah, there are major problems with whatever the bundler is doing (tree shaking). I'm pretty confident this has nothing to do with GSAP.

 

Even when I figured out a way to prevent it from dropping the Linear object (which it never should have done anyway), it just ran into more problems because it literally dropped the gsap object itself! I'd say it's clearly bugs/problems in whatever the build process is doing. I definitely wouldn't recommend trusting that with your assets. Maybe there's some kind of configuration you must do to make it less aggressive/buggy but I'm not at all familiar with Angular or the Angular AoT. 

  • Like 1
Link to comment
Share on other sites

It al has to do with what your (Angular) project is using or not. When simply importing specific imports from gsap the bundler includes only that specific objects & its dependencies. The plugin registration (in the way it is currently set up) and the initialisation of gsap is skipped.

That can be simply changed: Import the plugins you need & the gsap object. For Angular somewhere in the top op your main.ts file.

import { EaselPlugin, gsap } from "gsap/all";

gsap.registerPlugin(EaselPlugin);

 

Link to comment
Share on other sites

3 hours ago, Nexib said:

It al has to do with what your (Angular) project is using or not. When simply importing specific imports from gsap the bundler includes only that specific objects & its dependencies. The plugin registration (in the way it is currently set up) and the initialisation of gsap is skipped.

That can be simply changed: Import the plugins you need & the gsap object. For Angular somewhere in the top op your main.ts file.

import { EaselPlugin, gsap } from "gsap/all";

gsap.registerPlugin(EaselPlugin);

 

I try import in main.js with your code but, nothing..... Same problem in AoT mode....

Link to comment
Share on other sites

Yeah, I verified yesterday that the bundler is inappropriately dropping things that are essential...even things that are referenced in the file itself that end up getting [partially] included in the final result! Clearly a bug in the bundler. I'd recommend contacting the author(s) of that project and inquiring about how to fix that - maybe there's a configuration that'd resolve things. 

Link to comment
Share on other sites

  • 2 years later...

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