PostHog / posthog-node

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

PosHog is not a constructor #76

Closed 03-01-0v0 closed 2 years ago

03-01-0v0 commented 2 years ago

Hi, I am getting the following error with posthog-node Here is my package.json file : { "name": "test", "version": "1.0.0", "description": "", "main": "index.js", "type": "module", "scripts": { "start": "node src/index.js", "dev": "nodemon src/index.js" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "express": "^4.18.1", "nodemon": "^2.0.19", "posthog-node": "^2.0.1" } } Code with posthog in index.js . file : import PostHog from 'posthog-node'

const client = new PostHog( 'phc_UbdQ93ylhwFK2K2loRAyZrKOKtdNzhyryieuteir', { host: 'https://app.posthog.com' } // You can omit this line if using PostHog Cloud )

client.shutdown() --> there will be an error message PostHog is not a constructor. Pls help me.

sondcdev commented 2 years ago

Try to import { PostHogGlobal } instead of PostHog and also initialize the client by PostHogGlobal, too. It worked for me!

neilkakkar commented 2 years ago

Sorry about that, will update the docs, we've also updated the library to work with import { PostHog }.

Fixed by https://github.com/PostHog/posthog-js-lite/pull/16