Typeform/js-api-client

Typeform API client not compatible with Cloudflare workers / Vercel edge runtime

Opened this issue ยท 6 comments

The current version of the Typeform API client does not run well on a Cloudflare worker / Vercel edge runtime. Creating a client result in the following error:

ReferenceError: window is not defined
    at (../../../../node_modules/.pnpm/@typeform+api-client@1.8.0/node_modules/@typeform/api-client/dist/typeform-api.js:1:209)
    at (../../../../node_modules/.pnpm/@typeform+api-client@1.8.0/node_modules/@typeform/api-client/dist/typeform-api.js:1:68)
    at (../../../../node_modules/.pnpm/@typeform+api-client@1.8.0/node_modules/@typeform/api-client/dist/typeform-api.js:1:170)
...

This is most probably caused by the (3 year old..) dependency to Axios. A switch to fetch should not only resolve the compatibility issue, but render the project free from build dependencies.

Hello @magnuslundin

can you please show us how you are using the library? How do you import it? The dist/typeform-api.js file is intended to be used in a browser, not server-side which might be causing your issue.

Also, the axios dependency was updated recently. Please try with the latest version of the lib.

Hello @magnuslundin

can you please show us how you are using the library? How do you import it? The dist/typeform-api.js file is intended to be used in a browser, not server-side which might be causing your issue.

Also, the axios dependency was updated recently. Please try with the latest version of the lib.

I'm using the library in a SvelteKit project deployed on Vercel. The typeform api client works well with the regular serverless functions (node). When I switched to using their Edge functions, which are utilizing CloudFlare workers the library generated the errors described above.

I'm currently circumventing this by forcing the specific part of the app that uses your library to use the serverless runtime.

Nice that the dependency is updated. I'll give it a go.

Edit: updated problem explanation

Please let us know if the problem still remains with the latest version.

I just noticed you mentioned a different Typeform library - Embed SDK. This library is not intended to be used server side. However when used with eg. NextJS it should render an empty div server-side and populate it with the embed (iframe with your typeform) when rendered client side - see React NextJS demos.

If the issue persists please raise it in embed SDK with details.

Hi @mathio,
Sorry for the confusion. It was a long time ago I posted the issue and I mixed up my typeform-challenges when this popped up :)

I've updated my comment above with the actual issue I was facing.

Version 1.15.0 of the client has now been tested with the same result. Axios does not play well on cloudflare workers.

Thank you. I dont have much experience with Cloudflare workers, but I can test with Vercel.