posthog-node icon indicating copy to clipboard operation
posthog-node copied to clipboard

posthog.getAllFlags not working

Open SebTVisage opened this issue 2 years ago • 6 comments

Hi. I'm using posthog-node 2.0.2 and I get the following error when calling getAllFlags:

TypeError: undici__default.default.fetch is not a function
    at PostHogClient.fetch (/node_app/back/api/node_modules/@visage/visage-server-common/node_modules/posthog-node/src/posthog-node.ts:53:19)
    at /node_app/back/api/node_modules/@visage/visage-server-common/node_modules/posthog-core/src/index.ts:647:33
    at /node_app/back/api/node_modules/@visage/visage-server-common/node_modules/posthog-core/src/utils.ts:23:25
    at step (/node_app/back/api/node_modules/@visage/visage-server-common/node_modules/node_modules/tslib/tslib.es6.js:102:23)
    at Object.next (/node_app/back/api/node_modules/@visage/visage-server-common/node_modules/node_modules/tslib/tslib.es6.js:83:53)
    at fulfilled (/node_app/back/api/node_modules/@visage/visage-server-common/node_modules/node_modules/tslib/tslib.es6.js:73:58)

SebTVisage avatar Aug 26 '22 15:08 SebTVisage

Hey @SebTVisage , what's getAll ?

neilkakkar avatar Aug 26 '22 15:08 neilkakkar

Ok actually it's the same with isFeatureEnabled.

Sorry I meant getAllFlags (mentioned in the docs). I've edited the issue

SebTVisage avatar Aug 26 '22 15:08 SebTVisage

Hmm, just tested the library again, I don't face the same.

How're you using the library? Some reproduction instructions would be nice.

neilkakkar avatar Aug 26 '22 16:08 neilkakkar

On a node 12 project using TS. I'll try to give you a reproduction repo. I do this more or less:

import { PostHog } from 'posthog-node';
import config from '../config';

export const postHogClient = new PostHog(config.thirdParties.posthog.apiKey, {
  personalApiKey: config.thirdParties.posthog.personalKey,
});

// In another file:
import { postHogClient } from '<path to file above>';
// In a function I do just something like this
const featureFlags = await postHogClient.getAllFlags('some-user-id');

I'll try to do a reproduction repo

SebTVisage avatar Aug 26 '22 16:08 SebTVisage

For a quick check, we're using node 16, try if that works? Might mean we need to update the supported node versions 🤔

neilkakkar avatar Aug 26 '22 16:08 neilkakkar

This will be fixed here but it does bump the minimum version to v14.7.0 https://github.com/PostHog/posthog-js-lite/pull/22

benjackwhite avatar Sep 08 '22 12:09 benjackwhite