Jump to content
Search Community

Problem importing ScrollTrigger in React

Brian Mwangi test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

I'm having trouble importing ScrollTrigger in my React app.
I'm importing it like this:
 

import {ScrollTrigger} from "gsap/ScrollTrigger";


This is the error  I'm getting and I don't know how to go about it. The error is coming from ScrollTrigger.js in the node_modules.
 

import { Observer, _getTarget, _vertical, _horizontal, _scrollers, _proxies, _getScrollFunc, _getProxyProp, _getVelocityProp } from "./Observer.js";
^^^^^^

SyntaxError: Cannot use import statement outside a module

Here is a pic of the ScrollTrigger.js file:
 

Screenshot from 2022-09-21 21-02-44.png

Link to comment
Share on other sites

  • Solution

It sounds like your environment doesn't understand ES Modules. That's an issue in your build tools (you could probably fix it with some kind of settings tweak), but the easiest solution is probably to just import the standard (non-module) version in the /dist/ directory:

 

// OLD (ES module)
import {ScrollTrigger} from "gsap/ScrollTrigger";

// NEW (standard ES5)
import {ScrollTrigger} from "gsap/dist/ScrollTrigger";

 

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