Jump to content
Search Community

Question from a noob - Gsap and npm

Phelar test
Moderator Tag

Recommended Posts

Hi!

 

I´m trying to get started with gsap, but i need some help.

 

This is my html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">    
    <meta name="keywords" content="HTML, JavaScript">    
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <style>
        .test {
            background-color: black;
        }
    </style>
</head>
    <body>
        <div class="test">
            <img class="duck" src="/assets/anka.png" alt="Fin Anka">
        </div>
        
        <script type="module" src="node_modules/gsap/all.js"></script>
        <script type="module" src="/app.js"></script>
    </body>
</html>

and this is my .js:

 

import {gsap} from './node_modules/gsap'

gsap.to(".duck", {duration: 2, x: 300})

AND this is the error:

 

image.png.0a803fa24e9704e535e3130e0486a227.png

Link to comment
Share on other sites

Ok, i solved this issue but i get this error when trying to import the gsap module like this
 

import { gsap } from "gsap"

 i get this error: Uncaught TypeError: Failed to resolve module specifier "gsap". Relative references must start with either "/", "./", or "../"
though i can reach and implement the method from the module

 

gsap.to(".duck", {duration: 2, x: 300})

 

 

Link to comment
Share on other sites

Why are you opting to use the modules version of GSAP? Most the time if you're using script tags you should load the non-modules version. I highly recommend going through the video about loading GSAP via the script tag in the installation documentation.

 

As for the issue, you'll need to give the full path to the modules version of GSAP if you want to do it that way.

Link to comment
Share on other sites

22 hours ago, ZachSaucier said:

Why are you opting to use the modules version of GSAP? Most the time if you're using script tags you should load the non-modules version. I highly recommend going through the video about loading GSAP via the script tag in the installation documentation.

 

 

I don´t have a good answere to that :) I gues it feels more like home...
I´ll try the non-module version.

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