Description
Description
After migrating from v4 to v5 (which was confusing in itself, as others have mentioned), I'm encountering weird issues with the algolia client in production. Such as: algolia.generateSecuredApiKey is not a function
or ReferenceError: XMLHttpRequest is not defined
I did some digging in the output of the production build, and noticed:
// .wrangler/tmp/chunks/_/algolia.mjs
function algoliasearch(appId, apiKey, options) {
return {
...searchClient(appId, apiKey, {
timeouts: {
connect: DEFAULT_CONNECT_TIMEOUT_BROWSER$3,
read: DEFAULT_READ_TIMEOUT_BROWSER$3,
write: DEFAULT_WRITE_TIMEOUT_BROWSER$3,
},
requester: createXhrRequester(),
algoliaAgents: [{ segment: 'Browser' }],
authMode: 'WithinQueryParameters',
responsesCache: createMemoryCache$3(),
requestsCache: createMemoryCache$3({ serializable: false }),
hostsCache: createFallbackableCache$3({
caches: [createBrowserLocalStorageCache$3({ key: `${apiClientVersion}-${appId}` }), createMemoryCache$3()],
}),
...options,
}),
/**
* And other methods from the full client, not relevant to this issue
*/
};
}
Apparently the browser build is used, and not the node js build. But I can't figure why this is happening...
I'm using a Nitro server in a CF workers environment. Version of Algolia client is 5.2.5, but it's been having this issue since at least 5.2.1
for context, this is how the client is set up 👇
// utils/algolia.ts
import { algoliasearch } from "algoliasearch";
export const useSearch = (opt: { session: Session}) => {
const { appId, publicKey } = useRuntimeConfig().algoliaSearch.onderwijsloket
const client = algoliasearch(
appId,
opt.session?.algolia?.apiKey ? opt.session.algolia.apiKey : publicKey,
{
baseHeaders: {
'X-Algolia-UserToken': opt.session?.itemId || 'anonymous',
}
}
)
return client
}
Client
All
Version
5.2.5
Relevant log output
No response