Stack Trace

Displays formatted JavaScript/Node.js error stack traces with syntax highlighting and collapsible frames.

The StackTrace component displays formatted JavaScript/Node.js error stack traces with clickable file paths, internal frame dimming, and collapsible content.

Install using CLI

AI Elements Vue
shadcn-vue CLI
npx ai-elements-vue@latest add stack-trace

Install Manually

Copy and paste the following files into the same folder.

StackTrace.vue
StackTraceHeader.vue
StackTraceError.vue
StackTraceErrorType.vue
StackTraceErrorMessage.vue
StackTraceActions.vue
StackTraceCopyButton.vue
StackTraceExpandButton.vue
StackTraceContent.vue
StackTraceFrames.vue
context.ts
utils.ts
index.ts
<script setup lang="ts">
import type { HTMLAttributes } from 'vue'
import type { ParsedStackTrace } from './context'
import { cn } from '@repo/shadcn-vue/lib/utils'
import { useVModel } from '@vueuse/core'
import { computed, provide } from 'vue'
import { StackTraceKey } from './context'
import { parseStackTrace } from './utils'

interface Props extends /* @vue-ignore */ HTMLAttributes {
  trace: string
  modelValue?: boolean
  defaultOpen?: boolean
  class?: HTMLAttributes['class']
}

const props = withDefaults(defineProps<Props>(), {
  defaultOpen: false,
  modelValue: undefined,
})

const emit = defineEmits<{
  (e: 'update:modelValue', value: boolean): void
  (e: 'openChange', value: boolean): void
  (e: 'filePathClick', filePath: string, line?: number, column?: number): void
}>()

const isOpen = useVModel(props, 'modelValue', emit, {
  defaultValue: props.defaultOpen,
  passive: true,
})

const parsedTrace = computed<ParsedStackTrace>(() => parseStackTrace(props.trace))

function onFilePathClick(filePath: string, line?: number, column?: number) {
  emit('filePathClick', filePath, line, column)
}

function setIsOpen(value: boolean) {
  isOpen.value = value
  emit('openChange', value)
}

provide(StackTraceKey, {
  trace: parsedTrace,
  raw: computed(() => props.trace),
  isOpen,
  setIsOpen,
  onFilePathClick,
})
</script>

<template>
  <div
    :class="cn(
      'not-prose w-full overflow-hidden rounded-lg border bg-background font-mono text-sm',
      props.class,
    )"
    v-bind="$attrs"
  >
    <slot />
  </div>
</template>

Features

  • Parses standard JavaScript/Node.js stack trace format
  • Highlights error type in red
  • Dims internal frames (node_modules, node: paths)
  • Collapsible content with smooth animation
  • Copy full stack trace to clipboard
  • Clickable file paths with line/column numbers

Examples

Collapsed by Default

Hide Internal Frames

Props

<StackTrace />

tracerequiredstring
The raw stack trace string to parse and display.
v-modelboolean
Controlled open state (uses modelValue internally).
defaultOpenboolean
Whether the content is expanded by default.
@update:modelValue(value: boolean) => void
Callback when open state changes.
@openChange(value: boolean) => void
Callback when open state changes (alternative to @update:modelValue).
@filePathClick(path: string, line?: number, column?: number) => void
Callback when a file path is clicked. Receives the file path, line number, and column number.
...propsHTMLAttributes
Spread to the root div.

<StackTraceHeader />

...propsCollapsibleTriggerProps
Spread to the CollapsibleTrigger.

<StackTraceError />

...propsHTMLAttributes
Spread to the container div.

<StackTraceErrorType />

defaultSlot
Custom content. Defaults to the parsed error type.
...propsHTMLAttributes
Spread to the span element.

<StackTraceErrorMessage />

defaultSlot
Custom content. Defaults to the parsed error message.
...propsHTMLAttributes
Spread to the span element.

<StackTraceActions />

...propsHTMLAttributes
Spread to the container div.

<StackTraceCopyButton />

@copy() => void
Callback fired after a successful copy.
@error(error: Error) => void
Callback fired if copying fails.
timeoutnumber
How long to show the copied state (ms).
...propsButtonProps
Spread to the underlying Button component.

<StackTraceExpandButton />

...propsHTMLAttributes
Spread to the container div.

<StackTraceContent />

maxHeightnumber
Maximum height of the content area (in pixels).
...propsCollapsibleContentProps
Spread to the CollapsibleContent.

<StackTraceFrames />

showInternalFramesboolean
Whether to show internal frames (node_modules, node: paths).
...propsHTMLAttributes
Spread to the container div.