Jump to content
Search Community

Using splitText, got this error: "Cannot use import statement outside a module"

Vander test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

Hello buds :)

 

I think i've found an error using astro and gsap(?). I've found something similar in Nuxt but I wasn't able to solve it by myself (sorry :/ )

 

Thing is, i've registered SplitText plugin and created and astro component, imported module and everything was working ok. Then, I translated the astro component to Vue component and my problems appeared. I get an error saying "Cannot use import statement outside a module", but i added "type="module" to the component and package.json and still getting the error
image.png.30574b59670651473a974defc2991d7e.png

I'm not sharing my .npmrc file for obvious reasons haha
 

Does anyone know how to solve it or what i'm doing wrong?  

 

Thanks!

 

package.json:

CapturadePantalla2023-04-24ales16_33_18.png.8c919bf0bdfe5f7294c438744693b07d.png

Vue component:

CapturadePantalla2023-04-24ales16_33_34.thumb.png.2c49247ff46ff9ad3830e4708056eca5.png

Error:

CapturadePantalla2023-04-24ales16_34_14.thumb.png.cbb2f578304534290beaafdc0fa32761.png

More info about the error:

CapturadePantalla2023-04-24ales16_33_05.thumb.png.bb5091175c04d52714e1221951472466.png

 

Link to comment
Share on other sites

  • Solution

It's pretty tough to diagnose just by looking at some error messages, but it sounds like you must have some code referencing SplitText in your framework that's getting compiled down and your build system doesn't understand modules. Perhaps try changing your import statements to reference the UMD files in the /dist/ directory, like: 

// old
import SplitText from "gsap/SplitText";

// new
import SplitText from "gsap/dist/SplitText";

 

Also, I believe that browsers require your imports to end in ".js" and refer to a valid location when you use type="module" in your <script> tag. 

 

By the way, did you sign up for a Club GreenSock in a different account? I don't see a membership associated with your account. I'm curious how you got access to SplitText. 

  • Like 1
Link to comment
Share on other sites

56 minutes ago, GreenSock said:

It's pretty tough to diagnose just by looking at some error messages, but it sounds like you must have some code referencing SplitText in your framework that's getting compiled down and your build system doesn't understand modules. Perhaps try changing your import statements to reference the UMD files in the /dist/ directory, like: 

// old
import SplitText from "gsap/SplitText";

// new
import SplitText from "gsap/dist/SplitText";

 

Also, I believe that browsers require your imports to end in ".js" and refer to a valid location when you use type="module" in your <script> tag. 

 

By the way, did you sign up for a Club GreenSock in a different account? I don't see a membership associated with your account. I'm curious how you got access to SplitText. 

Sure, i'll try to change the import statement as soon as I arrive at my work computer tomorrow morning(I forgot to push changes to git lol)

 

I think i've tried the ".js" ending, but was failing also. I'll also try it!

 

About the account, yeah, i signed up in my work account. I like to have stuff separate in my personal acc and my working acc

 

I'll keep you updated, thanks! :)

Link to comment
Share on other sites

10 hours ago, GreenSock said:

It's pretty tough to diagnose just by looking at some error messages, but it sounds like you must have some code referencing SplitText in your framework that's getting compiled down and your build system doesn't understand modules. Perhaps try changing your import statements to reference the UMD files in the /dist/ directory, like: 

// old
import SplitText from "gsap/SplitText";

// new
import SplitText from "gsap/dist/SplitText";

 

Also, I believe that browsers require your imports to end in ".js" and refer to a valid location when you use type="module" in your <script> tag. 

 

By the way, did you sign up for a Club GreenSock in a different account? I don't see a membership associated with your account. I'm curious how you got access to SplitText. 

Yeah, changing the import to gsap/dist/SplitText makes it work.

 

Is this an error from astro then? Should I write them?

 

Thanks :)

Link to comment
Share on other sites

I'm glad that worked!

 

I'm not sure it's an "error" per se - it sounds like their build system just hasn't been modernized to recognize modules or maybe there's a configuration step on your end that you missed that allows your build tool to compile things in the proper order. It's worth asking the Astro folks maybe. 

 

Good luck!

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