-
Notifications
You must be signed in to change notification settings - Fork 206
feat: add nuxt support #2372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: add nuxt support #2372
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6ad5d62
feat: move posthog cli call to core
ablaszkiewicz 7fddf84
feat: wip
ablaszkiewicz 56fccce
feat: wip
ablaszkiewicz 7b7ede5
feat: wip
ablaszkiewicz 734110f
feat: wip
ablaszkiewicz 74f951d
feat: update example readme
ablaszkiewicz 0bba43a
feat: wip
ablaszkiewicz 587178e
fix: lint
ablaszkiewicz 9ada812
feat: update nuxt module readme
ablaszkiewicz 27d3c65
feat: add changeset
ablaszkiewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@posthog/nuxt': patch | ||
| --- | ||
|
|
||
| add posthog nuxt package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Nuxt dev/build outputs | ||
| .output | ||
| .data | ||
| .nuxt | ||
| .nitro | ||
| .cache | ||
| dist | ||
|
|
||
| # Node dependencies | ||
| node_modules | ||
|
|
||
| # Logs | ||
| logs | ||
| *.log | ||
|
|
||
| # Misc | ||
| .DS_Store | ||
| .fleet | ||
| .idea | ||
|
|
||
| # Local env files | ||
| .env | ||
| .env.* | ||
| !.env.example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "trailingComma": "es5", | ||
| "tabWidth": 2, | ||
| "semi": false, | ||
| "singleQuote": true, | ||
| "printWidth": 120 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # PostHog Nuxt module Example | ||
|
|
||
| This interactive example demonstrates error tracking capabilities of PostHog's Nuxt module. | ||
|
|
||
| ## How to run | ||
|
|
||
| 1. Run `pnpm i` in the repo root. | ||
| 2. Run `pnpm build` in the repo root. | ||
| 3. Run `pnpm package` in the repo root. | ||
| 4. Run `pnpm i` inside this package. | ||
| 5. Run `pnpm build` inside this package. | ||
| 6. Run `node .output/server/index.mjs` inside this package | ||
|
|
||
| Now you can either visit `localhost:3000` and press buttons to throw frontend errors or visit `localhost:3000/error` to throw a nitro error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <template> | ||
| <div> | ||
| <NuxtRouteAnnouncer /> | ||
| <NuxtPage /> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // https://nuxt.com/docs/api/configuration/nuxt-config | ||
| export default defineNuxtConfig({ | ||
| modules: ['@posthog/nuxt'], | ||
| compatibilityDate: '2025-07-15', | ||
| devtools: { enabled: true }, | ||
| sourcemap: { client: 'hidden' }, | ||
| nitro: { | ||
| rollupConfig: { | ||
| output: { | ||
| sourcemapExcludeSources: false, | ||
| }, | ||
| }, | ||
| }, | ||
| posthogConfig: { | ||
| host: 'http://localhost:8010', | ||
| publicKey: process.env.POSTHOG_PROJECT_API_KEY!, | ||
| debug: true, | ||
| clientConfig: { | ||
| capture_exceptions: true, | ||
| }, | ||
| serverConfig: { | ||
| enableExceptionAutocapture: true, | ||
| }, | ||
| sourcemaps: { | ||
| enabled: true, | ||
| version: 'V1', | ||
| envId: '2', | ||
| project: 'i-love-nuxt-1', | ||
| personalApiKey: process.env.POSTHOG_PERSONAL_API_KEY!, | ||
| }, | ||
| }, | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "name": "example-nuxt-module", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "nuxt build", | ||
| "dev": "nuxt dev", | ||
| "generate": "nuxt generate", | ||
| "preview": "nuxt preview", | ||
| "postinstall": "nuxt prepare" | ||
| }, | ||
| "dependencies": { | ||
| "nuxt": "^3.19.3", | ||
| "vue": "^3.5.22", | ||
| "vue-router": "^4.5.1", | ||
| "@posthog/nuxt": "*" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| <template> | ||
| <div style="padding: 20px; font-family: sans-serif"> | ||
| <h1>Error Testing Page</h1> | ||
| <p>Test various hard-to-catch errors:</p> | ||
|
|
||
| <div style="display: flex; flex-direction: column; gap: 10px; max-width: 400px"> | ||
| <button @click="throwSimpleError" style="padding: 10px; cursor: pointer">1. Simple Synchronous Error</button> | ||
|
|
||
| <button @click="throwUncaughtPromiseRejection" style="padding: 10px; cursor: pointer"> | ||
| 2. Uncaught Promise Rejection | ||
| </button> | ||
|
|
||
| <button @click="throwAsyncError" style="padding: 10px; cursor: pointer"> | ||
| 3. Async Function Error (no catch) | ||
| </button> | ||
|
|
||
| <button @click="throwTimeoutError" style="padding: 10px; cursor: pointer">4. setTimeout Error</button> | ||
|
|
||
| <button @click="throwPromiseChainError" style="padding: 10px; cursor: pointer">5. Promise Chain Error</button> | ||
|
|
||
| <button @click="throwEventLoopError" style="padding: 10px; cursor: pointer">6. NextTick/Event Loop Error</button> | ||
|
|
||
| <button @click="throwNestedAsyncError" style="padding: 10px; cursor: pointer">7. Nested Async Error</button> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { throwSimpleError as utilThrowError } from '~/utils/errorUtils' | ||
|
|
||
| // 1. Simple synchronous error | ||
| const throwSimpleError = () => { | ||
| utilThrowError() | ||
| } | ||
|
|
||
| // 2. Uncaught promise rejection | ||
| const throwUncaughtPromiseRejection = () => { | ||
| Promise.reject(new Error('Uncaught promise rejection!')) | ||
| // Intentionally no .catch() | ||
| } | ||
|
|
||
| // 3. Async function error | ||
| const throwAsyncError = async () => { | ||
| await new Promise((resolve) => setTimeout(resolve, 100)) | ||
| throw new Error('Async function error without catch!') | ||
| } | ||
|
|
||
| // 4. setTimeout error | ||
| const throwTimeoutError = () => { | ||
| setTimeout(() => { | ||
| throw new Error('Error thrown in setTimeout!') | ||
| }, 100) | ||
| } | ||
|
|
||
| // 5. Promise chain error | ||
| const throwPromiseChainError = () => { | ||
| Promise.resolve() | ||
| .then(() => { | ||
| return Promise.resolve('step 1') | ||
| }) | ||
| .then(() => { | ||
| throw new Error('Error in promise chain!') | ||
| }) | ||
| } | ||
|
|
||
| // 6. Error in nextTick | ||
| const throwEventLoopError = () => { | ||
| nextTick(() => { | ||
| throw new Error('Error in nextTick!') | ||
| }) | ||
| } | ||
|
|
||
| // 7. Nested async error | ||
| const throwNestedAsyncError = () => { | ||
| const innerAsync = async () => { | ||
| await new Promise((resolve) => setTimeout(resolve, 50)) | ||
| throw new Error('Nested async error!') | ||
| } | ||
|
|
||
| const outerAsync = async () => { | ||
| innerAsync() | ||
| } | ||
|
|
||
| outerAsync() | ||
| } | ||
| </script> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.