Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
oligsap

Importing ScrollToPlugin ES6 Babel Webpack NPM

Recommended Posts

Hello community !

 

I'm having trouble importing plugins. I use the gsap npm doc with gsap v2.0.2.

 

When I use this :

 

import { TweenMax } from 'gsap';

 

TweenMax works perfectly fine.

 

But when I want to use the scrollToPlugin with this for example :

 

TweenMax.to('.my-div', 2, { scrollTo: { y: 'max' } });

 

I do this : 

 

import { TweenMax, ScrollToPlugin } from "gsap/TweenMax";

or

import { TweenMax, ScrollToPlugin } from "gsap/all";

 

I get errors saying :

 

TweenMax.js:13 Uncaught SyntaxError: Unexpected identifier

or

all.js:13 Uncaught SyntaxError: Unexpected identifier

 

Thank you very much for your help !

Link to comment
Share on other sites

ScrollToPlugin is NOT included in the TweenMax file, so this won't work: 

//BAD:
import { TweenMax, ScrollToPlugin } from "gsap/TweenMax";

 

But this certainly should work: 

//GOOD:
import { TweenMax, ScrollToPlugin } from "gsap/all";

 

You could also try this:

import TweenMax from "gsap/TweenMax";
import ScrollToPlugin from "gsap/ScrollToPlugin";

 

You're using files installed via NPM, right? That error message almost sounds like you're using the old UMD files in an environment that's expecting ES6 modules. 

 

You don't have tree shaking enabled, do you? 

 

It's pretty tough to diagnose blind. If you still need some help, could you provide a reduced test case? Maybe in codesandbox or github? 

  • Like 2
Link to comment
Share on other sites

So your code suggestions didn't work : still getting the errors.

 

Regarding tree shaking, I'm sorry I read the documentation but I don't understand what it is. Plus, I'm using webpack 2 & gulp 4 in my workflow so it's a little difficult to follow the examples.

 

BUT

 

Your thoughts regarding old UMD files and ES6 helped me. I solved my problem doing this :

 

import { TweenMax } from 'gsap';
import ScrollToPlugin from 'gsap/umd/ScrollToPlugin';

 

Thank you very much !

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