-
Notifications
You must be signed in to change notification settings - Fork 2
Error using in SvelteKit? #3
Comments
@kenjonespizza Thanks for the reproduction and the detailed analysis. I've encountered this error a few times myself in the past. It was usually enough to add one of these to vite: {
optimizeDeps: {
exclude: ["algoliasearch"],
},
ssr: {
noExternal: true,
},
}, Just tried it on your repo and didn't help. This must have broken quite recently as I use |
Thanks @janosh ! I was hoping a SvelteKit update was the culprit and not me, since I had seen it working on your sites. I even attempted matching your "svelte" and "@sveltejs/kit" versions in the package.json and still no dice. I don't currently need this for a project, but will likely keep tinkering. 👍 |
Good to know. Back from work now and had another look at it. As expected, everything works fine if I replace import algoliasearch from 'algoliasearch/lite.js' with <svelte:head>
<script src="https://cdn.jsdelivr.net/npm/algoliasearch@4.5.1/dist/algoliasearch-lite.umd.js"></script>
</svelte:head> in |
Oh cool. Completely up to you sir if you want to release that. I'd be more than happy with it, but I want it to bring you joy, whereas it's just a temporary workaround. Maybe it maks since to put it behind a flag/option, OR maybe that just convolutes a decision the user shouldnt need to make? My vote is to go ahead and push the fix :) . Thanks for being amazing and hopping in to this so quickly! |
Turns out there's an easier way to fix this. Instead of relying on the package structure when importing |
From initial testing, it looks like updating to |
Hi @janosh !
It's amazing that you made this package! I however can't get it to work with SvelteKit. I made a minimal site from scratch to replicate the issue: https://github.com/kenjonespizza/svelteKit-svelte-algolia-test (I kept the .env in there to assist). the site builds without error, but errors out in Dev mode.
The Error
It's one of those SvelteKit SSR Module errors I've seen times before but can never figure out how to actually fix, since the problem seems to be with the external package. I also messed around with the Vite config options... but once again can't find one that solved this for me. Below is a log of the main issue. Also attached is an image of my terminal log incase that easier to read.
[vite] Error when evaluating SSR module /node_modules/.pnpm/algoliasearch@4.12.0/node_modules/algoliasearch/lite.js?v=f431d156: ReferenceError: module is not defined
Thanks!
The text was updated successfully, but these errors were encountered: