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

Axios causing issues when using post hog-node in Next.js 12 middleware #60

Closed
weyert opened this issue Nov 30, 2021 · 2 comments
Closed

Comments

@weyert
Copy link

weyert commented Nov 30, 2021

Last month Vercel introduced middleware in their latest version of Next.js version 12. The middleware is using edge functions on their hosting environment but when you self-host on example GKE it also works but the same limitations apply.

If I am using posthog-node I am getting the following error:

Error: Error: Request to api/feature_flag failed with error: adapter is not a function
    at FeatureFlagsPoller._request (webpack-internal:///./node_modules/posthog-node/feature-flags.js:158:19)
    at async FeatureFlagsPoller._loadFeatureFlags (webpack-internal:///./node_modules/posthog-node/feature-flags.js:91:25)
    at async FeatureFlagsPoller.loadFeatureFlags (webpack-internal:///./node_modules/posthog-node/feature-flags.js:78:13)
    at async FeatureFlagsPoller.isFeatureEnabled (webpack-internal:///./node_modules/posthog-node/feature-flags.js:36:9)
    at async PostHog.isFeatureEnabled (webpack-internal:///./node_modules/posthog-node/index.js:255:16)
    at async Object.middleware [as handler] (webpack-internal:///./src/pages/_middleware.ts:26:28)
    at async adapter (webpack-internal:///./node_modules/next/dist/server/web/adapter.js:30:22)
    at async DevServer.runMiddleware (/Users/weyertdeboer/Development/Projects/xxx/app/projects/project/node_modules/next/dist/server/next-server.js:438:26)
    at async DevServer.runMiddleware (/Users/weyertdeboer/Development/Projects/xxx/app/projects/project/node_modules/next/dist/server/dev/next-dev-server.js:394:28)
    at async Object.fn (/Users/weyertdeboer/Development/Projects/xxx/app/projects/project/node_modules/next/dist/server/next-server.js:817:34)

I think this due to the use of Axios which is using XMLHttpRequest and this is not supported by the middleware functionality or their edge functions. There is a similar ticket at Next.js discussing this issue: vercel/next.js#30932

I am wondering if it's worth it to rewrite the library in a different library that might use fetch instead my limited scan of the code Axios appears to be mostly used for:

  • retry functionality
  • exponential backoff when retrying
  • throw error for non-ok response
  • automatically handling of json responses

I am happy to raise a PR to make these changes if people at PostHog are happy with this

@yakkomajuri
Copy link
Contributor

Sure, this could make sense!

@chris-aeviator
Copy link

what's the status of this?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants