typesense-js
typesense-js copied to clipboard
ApiCall.ts:244 Uncaught (in promise) TypeError: (0 , axios_1.default) is not a function
Description
Attempting to use the typesense package and more specifically the SearchClient on a create-react-app front-end. I keep getting the following error:
ApiCall.ts:244 Uncaught (in promise) TypeError: (0 , axios_1.default) is not a function
at ApiCall.ts:244:1
at step (AnalyticsRules.ts:41:1)
at Object.next (AnalyticsRules.ts:41:1)
at step (AnalyticsRules.ts:41:1)
at Object.next (AnalyticsRules.ts:41:1)
at fulfilled (AnalyticsRules.ts:41:1)
Steps to reproduce
The following code should be enough to reproduce this error:
const typesenseSearchClient = new SearchClient({
nodes: [
{
host: typesenseConfig.host || '',
port: 443,
protocol: 'https',
},
],
apiKey: typesenseConfig.apiKey || '',
connectionTimeoutSeconds: 2,
});
const params = {
q: query,
query_by: 'query1, query2',
filter_by: filters,
page: page + 1,
per_page: 20,
};
const res = await typesenseSearchClient.collections('collection').documents().search(params, {});
console.log(res);
Expected Behavior
I would expect to see some results in res.
Actual Behavior
Getting the error mentioned above and the app is crashing.
Metadata
Typesense Version: 1.8.2
OS: windows, create-react-app, node 21
This seems to be an issue specifically with create-react-app.
Here's what has worked for a few other users: https://stackoverflow.com/questions/76888080/react-app-throwing-axios-1-default-post-is-not-a-function-error/76906979#76906979