0

I am brand new to Astro.js. I've tried several ways to import a "global" function on another page but I always get an error saying the function "is not defined". Here is my code from the master/global layout page...

export function test1() {
    console.log('test1()');
}

And here is the code on a separate page...

import test1 from '../layouts/master.astro';

(later on that same page...)

setTimeout(() => {
    test1();
}, 100);

Any suggestions?

tvwxyz
  • 195
  • 3
  • 14

1 Answers1

1

Ah I figured it out. I updated the master page with the following code...

<script is:inline src="/global-methods.js"></script>
<script>
    setTimeout(() => {
        main();
    }, 100);
</script>

("global-methods.js" is in the public directory.) After doing that, I was able to reference my methods in subsequent pages.

tvwxyz
  • 195
  • 3
  • 14