Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
magnuslundin opened this issue Jul 6, 2023 · 9 comments
Labels
question Further information is requested

Comments

@magnuslundin
Copy link

magnuslundin commented Jul 6, 2023

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/@[email protected]/node_modules/@typeform/api-client/dist/typeform-api.js:1:209)
    at (../../../../node_modules/.pnpm/@[email protected]/node_modules/@typeform/api-client/dist/typeform-api.js:1:68)
    at (../../../../node_modules/.pnpm/@[email protected]/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.

@mathio mathio added the question Further information is requested label Oct 9, 2023
@mathio
Copy link
Contributor

mathio commented Oct 9, 2023

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.

@magnuslundin
Copy link
Author

magnuslundin commented Oct 10, 2023

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

@mathio
Copy link
Contributor

mathio commented Oct 10, 2023

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

@mathio
Copy link
Contributor

mathio commented Oct 12, 2023

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.

@mathio mathio closed this as completed Oct 12, 2023
@magnuslundin
Copy link
Author

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.

@mathio mathio reopened this Oct 23, 2023
@mathio
Copy link
Contributor

mathio commented Oct 23, 2023

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

@teamclouday
Copy link

I'm getting the same error on nextjs server side. Is there an API client for server side?

@magnuslundin
Copy link
Author

I'm getting the same error on nextjs server side. Is there an API client for server side?

No, there isn't. We have to make due creating our own implementations from this:
https://www.typeform.com/developers/responses/

@teamclouday
Copy link

I'm getting the same error on nextjs server side. Is there an API client for server side?

No, there isn't. We have to make due creating our own implementations from this: https://www.typeform.com/developers/responses/

Thank you! I was able to make it work by using fetch calls to the API directly, and cast the response to the types defined in this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants