Jump to content
Search Community

getting this error while importing GSAP in my project Uncaught ReferenceError: require is not defined

kiranjoshi test
Moderator Tag

Recommended Posts

try to import from the dist like

 

import gsap from "gsap/dist/gsap";
import ScrollTrigger from "gsap/dist/ScrollTrigger";

 

or 

 

 

import { gsap } from 'gsap';
import { ScrollTrigger } from 'gsap/dist/ScrollTrigger.js';

 

and don't forget to register the plugin after that

 

gsap.registerPlugin(ScrollTrigger);
  • Like 1
Link to comment
Share on other sites

Hi,

 

Is really hard for us to check issues and errors without a minimal demo.

 

The suggestion Toso made works when using on frameworks with some type of bundling/compiling system, like React/Next/Remix, Vue/Nuxt, Astro, etc. It seems to me that you are using Drupal. I know nothing about it but most likely there is no bundling system there, so you would have to use either the files in the ZIP file you can download or the CDN links and be sure to add them before your custom JS file:

https://cdnjs.com/libraries/gsap

 

You can learn more about it here:

https://gsap.com/docs/v3/Installation

 

Select the CDN tab in order to see how to use the GSAP files.

 

Hopefully this helps.

Happy Tweening!

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