Open viktorlarsson opened 1 year ago
Any temporarily solutions to this?
It would be a non-trivial amount of work to replace axios in typesense-js.
So the workaround would be to use say fetch
and call the Typesense HTTP APIs directly.
It's worth exploring have an edge/deno supported js/ts library as many users are switching to such implementations for their backend.
Related: https://github.com/typesense/typesense-js/issues/95
That axios is not working on edge workers like Deno Deploy, Vercel Edge Functions or Cloudflare Workers is an absolute dealbreaker for me.
You can just make fetch('<urhost>/collection/
) calls but it is annoying. That's what we do though.
I use pnpm aliases with redaxios
In my package.json
I specify:
"axios": "npm:redaxios@^0.5.1",
And I also have the following: .pnpmfile.cjs
function readPackage(pkg) {
if (pkg.dependencies && pkg.name === "typesense" && pkg.dependencies.axios) {
pkg.dependencies.axios = "npm:redaxios@^0.5.1";
}
return pkg;
}
module.exports = {
hooks: {
readPackage,
},
};
This setup works on Cloudflare Workers, not sure about other platforms.
Could we bump the version of axios to the latest one? I think the latest version of axios has the fetch
adapter which should work for runtimes other than node.
I just tried this out on typesense@2.0.0-0
(in a cloudflare worker) and get this error now:
[mf:err] TypeError: http_1.Agent is not a constructor
at null.<anonymous> (/Users/zwily/Source/bhr/node_modules/.pnpm/typesense@2.0.0-0_@babel+runtime@7.23.2/node_modules/typesense/src/Typesense/ApiCall.ts:223:38)
at step (/Users/zwily/Source/bhr/node_modules/.pnpm/tslib@2.6.2/node_modules/tslib/tslib.js:195:27)
at Object.next (/Users/zwily/Source/bhr/node_modules/.pnpm/tslib@2.6.2/node_modules/tslib/tslib.js:176:57)
at step (/Users/zwily/Source/bhr/node_modules/.pnpm/tslib@2.6.2/node_modules/tslib/tslib.js:180:143)
at Object.next (/Users/zwily/Source/bhr/node_modules/.pnpm/tslib@2.6.2/node_modules/tslib/tslib.js:176:57)
at fulfilled (/Users/zwily/Source/bhr/node_modules/.pnpm/tslib@2.6.2/node_modules/tslib/tslib.js:166:62)```
@jasonbosco I think that's because http
and https
node packages aren't compatible with Cloudflare worker. Should be a different issue i believe
@zwily http
and https
package were introduced in v1.9.0. You could use typesense v1.8.2 and install axios v1.7.2 to use Cloudflare worker - this is how I got it working. Hope that helps
Description
As described in this ticket, Axios is not supported (and I don't think it will in any time near future) and you cannot use this library on an Serverless edge functions for example like Vercel, AWS etc. (or any service worker like Cloudflare)
https://github.com/axios/axios/issues/5523
https://vercel.com/guides/library-sdk-compatible-with-vercel-edge-runtime-and-functions#library-recommendations
Steps to reproduce
Expected Behavior
Actual Behavior
it... should work :D
Metadata
Typesense Version: 1.5.4
OS: Mac OS X