PostHog / posthog-node

Official PostHog Node library
MIT License
21 stars 19 forks source link

posthog.getAllFlags not working #77

Open SebTVisage opened 1 year ago

SebTVisage commented 1 year ago

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)
neilkakkar commented 1 year ago

Hey @SebTVisage , what's getAll ?

SebTVisage commented 1 year ago

Ok actually it's the same with isFeatureEnabled.

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

neilkakkar commented 1 year ago

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

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

SebTVisage commented 1 year ago

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

neilkakkar commented 1 year ago

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

benjackwhite commented 1 year ago

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