Jump to content
Search Community

Nuxt + gsap/Draggable : Cannot use import statement outside a module

rmonell test
Moderator Tag

Go to solution Solved by ZachSaucier,

Recommended Posts

Hello

 

Today I encountered an issue while trying to use gsap/Draggable in a Nuxt project

 

I've imported the plugin like so :

import { gsap } from 'gsap'
import { Draggable } from 'gsap/Draggable'
 
gsap.registerPlugin(Draggable)

But here is the error I get :
 
image.thumb.png.c698ed468b8e89e569a899afb36a9cbb.png
 
Could someone explain me if there are a particulary maniupulation to use gsap plugins in Nuxt ?
 
Thank you in advance for your time !
Link to comment
Share on other sites

  • Solution

Hey rmonell. As covered in the installation docs, you should transpile GSAP. Put the following in your nuxt.config:

build: {
    ...
    transpile: ['gsap'],
},

Then you should be able to import GSAP and Draggable as such:

import { gsap } from "gsap";
import { Draggable } from "gsap/Draggable";

if (process.client) {
  gsap.registerPlugin(Draggable);
}

 

  • Like 3
  • 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...