Jump to content
Search Community

Visual Studio Code GSAP Install Error

DeltaFrog test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

Hi All,  I'm trying to start using Visual Studio Code and would like to get access to GSAP.  

 

I used "npm install gsap" to install gsap and that worked but when I add the import line in my script.js file I get an error.

 
image.png.ea9d6c04d34524c76fb07249c68298a2.png

 

html: 

Inkedvsc-sc3_LI.jpg.83168f3afddd94837d3b5e17634027fa.jpg

 

folder:

image.png.fcac87f882ecc0150ffc32aadadfc11d.png

 

image.thumb.png.00591504593e79913ad6730948f79f1e.png

 

 

What am I doing wrong?  :D

 

 

 

 

image.png

Link to comment
Share on other sites

You're running things in the browser with no build system - browsers don't know about node_modules. If you want to use it directly in the browser like that, you'd need to follow the directions in that error message - define a relative path from your document to the GSAP file(s), and make sure they end in ".js". 

import gsap from "./libs/gsap/gsap.js"; 

(that assumes you've got it in a directory structure like libs/gsap/gsap.js of course but you can structure it however you want.)

 

Honestly, I wouldn't really recommend using modules like that directly in the browser - I'd just use the .min.js (ES5) files because: 

  • They're universally compatible
  • They're compressed (faster to load)

Or switch to using a build tool that handles all that for you.

 

Good luck!

Link to comment
Share on other sites

  • Solution

It really depends on your project, if you're using a framework (like React or Angular), etc. I'm not an expert on build tools.

 

Frankly, I'd just stick with the plain vanilla .min.js <script> tags for most things whenever I can. You shouldn't feel pressured into setting up a whole build tool and environment. It's common to feel like the "cool kids" use all these complex build tools, NPM, modules, bundlers, etc. and therefore you should do it too but I don't subscribe to that mindset at all. Keep it simple when you can.

 

Are you saying it feels clunky to just use <script src="https://unpkg.co/gsap@3/dist/gsap.min.js"></script> for example? 

 

Others are welcome to chime in here with their build tool recommendations. 

 

Good luck!

  • Like 2
  • Thanks 1
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...