Hi,
I wasn't able to reproduce, everything looks correct...
Actually, I was expecting a different error, since Svelte can run both in the browser & the server, usually, you need to limit your code to a browser environment. Here's my usual setup:
import Counter from './Counter.svelte';
import welcome from '$lib/images/svelte-welcome.webp';
import welcome_fallback from '$lib/images/svelte-welcome.png';
import gsap from 'gsap';
import { onDestroy, onMount } from 'svelte';
let context:any;
let tl: GSAPTimeline;
// Specifies this is running in the browser
onMount(() => {
context = gsap.context(() => {
tl = gsap.timeline();
tl.to({}, {});
});
});
onDestroy(
()=> {
if(typeof context !== 'undefined'){
context.revert();
tl.clear();
}
}
);
Of course, this would work without gsap.context but I have struggled in the past when having different animations across multiple components & pages, so that approach helps me keep everything tidy
I haven't found a way to specify a type f or context though. It seems it should be
let context:Context2
but I haven't found a way to import the Context2 type