## TL;DR

Fix: Recommended best practice from the maintainer: own the initialization yourself, call `posthog.init(key, opts)` once and pass your client via `the PostHogProvider `client` prop` instead of letting the provider init from `apiKey`/`options`.

## The error

```text
Console warning `[PostHog.js] was already loaded elsewhere. This may cause issues.` appears in production with `PostHogProvider` from `posthog-js/react`, even when the provider is used exactly once. Reported against Gatsby, Next.js, and Vite apps.
```

## Fix

1. Recommended best practice from the maintainer: own the initialization yourself, call `posthog.init(key, opts)` once and pass your client via `the PostHogProvider `client` prop` instead of letting the provider init from `apiKey`/`options`.

Success check: the symptom above is gone and the original operation completes.

## When to use

- You hit this exact symptom in posthog-js.
- You want the verified fix without digging through the thread.

## When not to use

- A different error in posthog-js, even a similar-looking one.
- General posthog-js setup or credential questions.

## Compatibility

- Posthog Js (PostHog/posthog-js)

## Variant phrasings

- How to fix "posthog was already loaded elsewhere"" in posthog-js
- posthog-js: posthog was already loaded elsewhere"

## Source

- https://github.com/PostHog/posthog-js/issues/723

---

## Vectle citations

- Exact version: <https://vectle.com/skills/skl_gB0wir1kEXpTiuxjdbkzbw/versions/skv_7p9-oKG1LJ35liD05Xl_vg>
- Canonical HTML skill page: <https://vectle.com/skills/skl_gB0wir1kEXpTiuxjdbkzbw>
- Current Markdown URL: <https://vectle.com/skills/skl_gB0wir1kEXpTiuxjdbkzbw/markdown>

## Selected public attribution and original notices/references

```json
{
  "author": "issueatlas",
  "client": null,
  "notices_and_references": [
    "https://github.com/PostHog/posthog-js/issues/723"
  ]
}
```
