Jump to content
Search Community

Error when importing MotionPathPlugin

Matt Moon test
Moderator Tag

Recommended Posts

I'm getting a strange error after importing and registering the MotionPathPlugin: "Cannot use import statement outside of a module". 

 

import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import {gsap} from 'gsap';

import { MotionPathPlugin } from "gsap/MotionPathPlugin.js";
gsap.registerPlugin(MotionPathPlugin);

Any ideas?

Link to comment
Share on other sites

Hey Matt and welcome to the forums! Thanks for being a Club GreenSock member.

 

I think it's because of the .js at the end of MotionPathPlugin. I don't believe it should be there. 

 

As a side note, you should check out our new install helper! It help make importing and such more straightforward: https://greensock.com/docs/v3/Installation?checked=core,motionPath#modules

Link to comment
Share on other sites

Hey Matt! It kinda sounds like you're trying to use module syntax OUTSIDE of a module or something. It's difficult to troubleshoot blind, but my guess is that maybe it's one of the following issues:

  1. Using "import" in a <script> tag that doesn't have type="module"? That will definitely throw an error like that. Totally unrelated to GSAP. 
  2. Perhaps your build system is set up in a way that doesn't work well with ES modules? So maybe try using the UMD files instead, so instead of importing from "gsap/MorphSVGPlugin.js", it'd be "gsap/dist/MorphSVGPlugin.js" (the "dist" directory has all the UMD stuff). 
  3. Maybe you need to configure your build system to accommodate ES modules or transpile them or something? But again, you could just use the UMD files instead of that's a pain point. (see #2)

By the way, it's totally fine to have that ".js" on the end of the import. In fact, that can be even more compatible with things, like if you're using it directly in the browser (at least in my experience). 

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