#cannot use import statement outside a module

4 messages · Page 1 of 1 (latest)

velvet sparrow
#

I'm using the Vue integration, and trying to import the MotionPathPlugin for Greensock animation Platform, but i get the cannot use import statement outside a module. I'm confused because all the other import statements have worked fine in the component. I thought vue/astro would bundle all the code i'm using from node into a module for me?

<script setup lang="ts">
import {gsap} from "gsap" // works fine
import {MotionPathPlugin} from "gsap/MotionPathPlugin" // throws error
gsap.registerPlugin(MotionPathPlugin)

On the Astro side of things, it's hydrated client-side with

<VueComponent client:only="vue" />

The greensock docs mention adding lines to the build configuration, but I don't think that's the issue. My current work around has been to use

const MotionPathPlugin = await import("gsap/MotionPathPlugin")

which removes the error, though I don't understand these imports in context of astro/vue, client/server and why only some modules need this type of dynamic import. Is this the correct way to solve this? A higher level explanation of what's going on here would also be appreciated too, thanks!

GreenSock
ivory prawnBOT
#
Quiet in here?

It looks like no-one has responded to your question yet. People might not be available right now or don’t know how to answer your question. Want an answer while you wait? Try asking our experimental bot in #1095492539085230272.

velvet sparrow
#

I'm running into this issue again with another library https://mojs.github.io/, but this time the dynamic import statements don't work. It's returning an error saying

#
    at Object.<anonymous> (/Users/mliou/projects/solar-solstice/node_modules/@mojs/core/dist/mo.umd.js:6:9)
    at Module._compile (node:internal/modules/cjs/loader:1239:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1293:10)
    at Module.load (node:internal/modules/cjs/loader:1096:32)
    at Module._load (node:internal/modules/cjs/loader:935:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:168:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v19.4.0