Skip to content

How to use node module imports in Astro js #120760

Discussion options

You must be logged in to vote

The issue you're facing is that you're trying to import modules directly in the Astro file, which is not allowed in Astro. Astro files are a combination of HTML, CSS, and JavaScript, but the JavaScript code needs to be wrapped inside a <script> tag with a specific type attribute.

For your first code snippet (Image 1), the code seems to be correctly wrapped inside a <script> tag with the is:inline directive, which tells Astro to render the script inline in the HTML. However, the issue here might be related to the GSAP library and how it's being registered.

For the second code snippet (Image 2), you're attempting to import modules at the top level of the Astro file, which is not allowed. Im…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@vickkie
Comment options

@Hadikamali
Comment options

@karthikjn01
Comment options

Answer selected by vickkie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Programming Help Programming languages, open source, and software development.
3 participants