Immutable solution version
Missing `pkg.exports` in package.json
Complete solution
Posthog Js: missing pkg.exports in package.json. The verified fix is Fix: Maintainer hpouillot: use the dedicated `@posthog/react` package (same code, proper ESM exports) instead of `posthog-js/react`, docs at posthog.com/docs/libraries/react were updated to reflect this, and the issue was closed. Use this when you hit the symptoms above in posthog-js; not for unrelated posthog-js errors or general setup questions.
TL;DR
Fix: Maintainer hpouillot: use the dedicated @posthog/react package (same code, proper ESM exports) instead of posthog-js/react, docs at posthog.com/docs/libraries/react were updated to reflect this, and the issue was closed. Community workarounds that also worked: pnpm patch to add an exports map to posthog-js' package.json, or ssr: { noExternal: ['posthog-js'] } in vite.config.ts.
The error
`posthog-js` can't be used in ESM/SSR Node projects (Remix/Vite): package.json lacks the `exports` map, so `import { PostHogProvider } from 'posthog-js/react'` fails with `SyntaxError: Named export 'PostHogProvider' not found`, the ESM file is treated as CommonJS.Fix
- Maintainer hpouillot: use the dedicated
@posthog/reactpackage (same code, proper ESM exports) instead ofposthog-js/react, docs at posthog.com/docs/libraries/react were updated to reflect this, and the issue was closed. - Community workarounds that also worked:
pnpm patchto add anexportsmap to posthog-js' package.json, orssr: { noExternal: ['posthog-js'] }in vite.config.ts.
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 "missing pkg.exports in package.json" in posthog-js
- posthog-js: missing pkg.exports in package.json
Source
- https://github.com/PostHog/posthog-js/issues/908
Evidence
In gh:PostHog/posthog-js#908 (https://github.com/PostHog/posthog-js/issues/908), the question was: posthog-js can't be used in ESM/SSR Node projects (Remix/Vite): package.json lacks the exports map, so import { PostHogProvider } from 'posthog-js/react' fails with SyntaxError: Named export 'PostHogProvider' not found, the ESM file is treated as CommonJS. The verified resolution: Maintainer hpouillot: use the dedicated @posthog/react package (same code, proper ESM exports) instead of posthog-js/react, docs at posthog.com/docs/libraries/react were updated to reflect this, and the issue was closed. Community workarounds that also worked: pnpm patch to add an exports map to posthog-js' package.json, or ssr: { noExternal: ['posthog-js'] } in vite.config.ts.
By @issueatlas · Version 2 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_xE8_SNG4vs_6bbgGp5xAhg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Missing `pkg.exports` in package.json <span>— Vectle</span></a>