Jump to content
GreenSock

Filip Winiarski

ScrollToPlugin not working in production build

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi,

I have been working on a scrollTo feature using ScrollToPlugin. It's working all fine on local environment, however after a production build in Angular (7.0.1 to be exact) tween throws famous scrollTo error:
 

Failed to execute 'scrollTo' on 'Window': parameter 1 ('options') is not an object.


This is how I import GSAP modules:
 

import { TweenMax, Power3 } from 'gsap'
import 'gsap/ScrollToPlugin'

 

console.log(com.greensock.plugins.ScrollToPlugin.version) // 1.9.1
console.log(com.greensock.TweenMax.version) // 2.0.2


And this is how I tween:
 

TweenMax.to(window, duration, { scrollTo: y, ease: Power3.easeInOut })


buildOptimizer for Angular is set to false. Import from 'gsap/all' neither works in a production build.

What am I missing? :)

 

SOLUTION:

 

Angular client is tree shaking so I had to reference ScrollToPlugin just after the import. Credits to @Rodrigo :)
 

import { TweenMax, Power3, ScrollToPlugin } from 'gsap/all'

const plugins = [ ScrollToPlugin ]



Angular: 7.0.1
Gsap: 2.0.2

  • Like 1
Link to comment
Share on other sites

Hi,

 

I'm not very familiar with how the latest versions of Angular are bundled, so I'll guess that it uses webpack and perhaps you're bundling with a create app type-CLI. If that's the case, the culprit could be tree shaking. Please read this:

 

https://greensock.com/docs/NPMUsage

 

More specifically the tree shaking part (just scroll down a bit) and let us know how it goes.

 

Happy Tweening!!

  • Like 5
  • Thanks 1
Link to comment
Share on other sites

7 minutes ago, Rodrigo said:

Hi,

 

I'm not very familiar with how the latest versions of Angular are bundled, so I'll guess that it uses webpack and perhaps you're bundling with a create app type-CLI. If that's the case, the culprit could be tree shaking. Please read this:

 

https://greensock.com/docs/NPMUsage

 

More specifically the tree shaking part (just scroll down a bit) and let us know how it goes.

 

Happy Tweening!!


That was the thing, thank you :) I will update the post with the solution, thanks!

  • Like 3
Link to comment
Share on other sites

  • 9 months later...

Thanks  for pointing out the tree shaking. I can confirm that the same occurs for VueJs - CLI 3. All worked great in development but as soon as I tested in production it would break. I was pulling out my hair for a few hours on this but it turned out to be tree shaking. 

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