DeltaFrog Posted April 29, 2022 Share Posted April 29, 2022 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. html: folder: What am I doing wrong? Link to comment Share on other sites More sharing options...
GreenSock Posted April 29, 2022 Share Posted April 29, 2022 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 More sharing options...
DeltaFrog Posted April 30, 2022 Author Share Posted April 30, 2022 Thanks Jack, I see what you are sayin, this workflow seems a bit clunky, what build tool do you recommend? Link to comment Share on other sites More sharing options...
Solution GreenSock Posted May 1, 2022 Solution Share Posted May 1, 2022 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! 2 1 Link to comment Share on other sites More sharing options...
DeltaFrog Posted May 1, 2022 Author Share Posted May 1, 2022 Got it, thanks Jack. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now