See Sanity in action 👀 Join us for a live product demo + Q&A →

Troubleshooting the compatibility of the sanity-algolia plugin with Netlify and Studio v3

19 replies
Last updated: Mar 4, 2023
I try to use the plugin sanity-algolia with netlify, but it doesn't work with studio v3. How do I get this working with v3and
user H
do you plan to upgrade this plugin to work with v3?
Feb 21, 2023, 1:53 PM
I haven’t heard of any timelines for when or if that plugin will be officially migrated. If you’re in dire need of it, though, you can follow this guide to migrate it to V3.
Feb 21, 2023, 8:26 PM
That plugin is purely a serverless function helper, so it should not depend on a particular version of the Studio. I believe the “v2 only” tagging on the exchange may be wrong. Can you provide some more detail on what did not work, or have you not tried it yet?
Feb 22, 2023, 6:55 PM
user H
, thanks for the reply. I try to get your TypeScript example (Vercel) running on Netlify, but I don't get it working with the Netlify type HandlerEvent and HandlerContext. In your example it is the part: return sanityAlgolia.webhookSync(sanity, body) where body needs to be of the type WebhookBody, where as HandlerEvent body is of type string. Any help would be appreciated.
Feb 24, 2023, 4:43 PM
Maybe you have the example typescript code for Netlify functions?
Feb 24, 2023, 4:44 PM
Netlify have a different signature of their serverless handler, and a different way to return a response. I updated the example to the types they expose here , but I have not tested it. Please report back if you test this and I’ll update the github repo README with this example once confirmed working
Feb 24, 2023, 7:18 PM
Hi Rune, thanks for the example. I see 2 issues:
Mar 2, 2023, 9:06 AM
1. sanityClient is depreciated, so that part should be replaced with const config: ClientConfig and const sanity = createClient(config)
Mar 2, 2023, 9:07 AM
2. The function netlifyHandler: Handler gives a TypeScript error: Type '(event: Event, context: Context) => Promise<void | Response>' is not assignable to type 'Handler'. Type 'Promise<void | Response>' is not assignable to type 'void | Promise<Response>'.
Type 'Promise<void | Response>' is not assignable to type 'Promise<Response>'.
Type 'void | Response' is not assignable to type 'Response'.
Type 'void' is not assignable to type 'Response'.
Mar 2, 2023, 9:08 AM
Thanks for the feedback
user Q
. I have updated the gist
Mar 2, 2023, 5:31 PM
user H
the errors are gone. Will test it tomorrow with data. Are you also involved with sanity-plugin-media? This package depends on an old v6 of which gives me could not resolve dependency (react 17) warnings:WARN peer react@"^16.8.0 || ^17" from react-hook-form@6.15.8
WARN node_modules/react-hook-form
WARN peer react-hook-form@">=6.6.0" from @hookform/resolvers@2.0.0-beta.3
Mar 2, 2023, 6:44 PM
Sorry,, I was too quick with my reply. Found 2 more issues:
Mar 2, 2023, 6:52 PM
1. It looks like sanity-algolia and @sanity/client are not using the same version of SanityClient. I get this message regarding sanity at the following call sanityAlgolia.webhookSync(sanity, JSON.parse(event.body)):Argument of type 'import("[root_dir]/node_modules/@sanity/client/dist/index").SanityClient' is not assignable to parameter of type 'import("[root_dir]/node_modules/sanity-algolia/node_modules/@sanity/client/sanityClient").SanityClient'.
Type 'SanityClient' is missing the following properties from type 'SanityClient': clientConfig, auth, isPromiseAPIts(2345)
Mar 2, 2023, 6:56 PM
So I think you only get the code running by updating the sanity client dependency in sanity-algolia package
Mar 2, 2023, 7:26 PM
It doesnt actually need a client, since you pass that in. The only reason its a dependency there is its type definitions, but thats not really required. I’m doing a PR to fix this. Meanwhile you can just install the same version of
as in the library
and it should work
Mar 2, 2023, 8:47 PM
Thanks for testing
Mar 2, 2023, 8:47 PM
Thanks for the quick fix. I'll wait for the new release, since I use sanity v3
Mar 2, 2023, 9:21 PM
I found another issue with the netlify example returning : TypeError - lambdaFunc[lambdaHandler] is not a function. This can be fixed by renaming netlifyHandler with handler.
Mar 4, 2023, 12:56 PM
I published the code to netlify and it is working. Thanks a lot
user H
! Last request, you mention in the example to add webhook secrets. Would be nice to update the example with working code to use a webhook secret if present in env file.
Mar 4, 2023, 6:49 PM – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in