I’ve been trying to export a static site using Algolia for a while but kept getting this not very helpful error message:
TypeError: instantsearch is not a function
Sma issue with SSR or completely static sites. O got this error during build time when running npm run build
. In my case, using Sveltekit.
I found this note on svelte-algolia-instantsearch that helped me solve the problem. I’m documenting here so if there’s anyone with the same issue, they won’t spend days trying to debug.
Compatibility with SvelteKit SSR
As instantsearch.js is currently not compatible with Node.js ESM modules, you need to add it to the ssr.noExternal array in your vite.config.js file:
// vite.config.js or vite.config.ts
const config = {
// ...
ssr: {
noExternal: ["instantsearch.js"],
},
};
The solution above worked perfectly.
It’d be great if someone from Algolia could clarify this issue and hopefully document the solution in the docs.