1

I am moving my blog to Astro and wanted to import some javascript using jquery.

In the Layout file I first import the jquery file (3.6.1) and then import my javascript file.

---
import "../scripts/jquery.js";
import "../scripts/main.js";
---

<!DOCTYPE html>
...

However I get the error (regarding the jquery file):

TypeError: Cannot read properties of undefined (reading 'document')
MGA
  • 23
  • 5

1 Answers1

0

Try importing your files with script tag :

<script src="../scripts/jquery.js"></script>
Moein Moeinnia
  • 1,945
  • 3
  • 10
  • 26
  • Yesterday I had tried it too but it didn't work; now it does (I think it is related to restarting the debugger). However, to make it really work I had to merge the two js into one file because otherwise it couldn't find jQuery. I think this is related to how Astro works. – MGA Sep 06 '22 at 10:07