-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sveltekit and svelte-lottie-player #7
Comments
same problem here, |
document is not defined on the server, so you need to guard against that in your component so that particular piece of code is only run in the browser. You can use the onMount function which is only run in the browser when the component has been rendered.
Sapper works well with most third-party libraries you are likely to come across. However, sometimes, a third-party library comes bundled in a way which allows it to work with multiple different module loaders. Sometimes, this code creates a dependency on window, such as checking for the existence of window.global might do. Since there is no window in a server-side environment like Sapper's, the action of simply importing such a module can cause the import to fail, and terminate the Sapper's server with an error such as: ReferenceError: window is not defined The way to get around this is to use a dynamic import for your component, from within the onMount function (which is only called on the client), so that your import code is never called on the server. Full working solution is provided below. Player.svelte
You may then import this module into other svelte components as needed. |
Tried above solution, still getting this error: Uncaught (in promise) SyntaxError: The requested module '/node_modules/lottie-web/build/player/lottie.js?v=9bced667' does not provide an export named 'default' |
|
Facing the same issue here @karamalie. From svelte.config.js: from svelte-kit route: ` <script> ... let LottiePlayer; onMount(async () => { const module = await import('@lottiefiles/svelte-lottie-player'); LottiePlayer = module.LottiePlayer; }); ... </script>
` Get the following error: Lottie-web installed as a dep. |
I was going through the same error when I tried using the svelte-lottie-player along with sveltekit. |
I think the error is with how the library pulls lottie-web |
Still not fixed in 2024? |
I get this error when building my project with an imported LottiePlayer
document is not defined ReferenceError: document is not defined
I read some other issue where they suggested adding this vite config item to the svelte.config.js
But that doesn't solve the issue for me.
The only thing that does is this code:
But this causes some ugly popin of the player. I want the animation to render on first draw. Any suggestions? Does LottiPlayer not work for static sites?
The text was updated successfully, but these errors were encountered: