Vue Ray Debugger
vue-ray is a utility designed for debugging Vue 3 applications by sending debugging information to the desktop Ray app. Currently at version 2.0.3, the package maintains an active release cadence, with notable updates including a major rewrite in v2.0.1. This rewrite transitioned the package to an ESM-first architecture and removed support for Vue 2 and Node.js versions below 18. It offers two primary integration methods: a global `RayPlugin` for application-wide configuration and a `raySetup()` composable for `<script setup>` contexts. The package's key differentiator is its seamless integration with the commercial Ray debugging application, providing a dedicated GUI for inspecting data, component lifecycle events, and errors, offering a richer debugging experience than traditional `console.log` methods.
Common errors
-
TypeError: (0 , vue_ray__WEBPACK_IMPORTED_MODULE_2__.RayPlugin) is not a function
cause Attempting to use `RayPlugin` in a project with `vue-ray` v2.0.1 or v2.0.2, where the export was temporarily broken.fixUpgrade `vue-ray` to version 2.0.3 or newer to resolve the missing export. -
Error: require() of ES Module ... vue-ray/dist/index.mjs not supported.
cause Using CommonJS `require()` syntax to import `vue-ray` v2.x, which is an ESM-first package.fixSwitch to ES Module `import` syntax: `import { RayPlugin } from 'vue-ray';`. -
TypeError: ray is not a function
cause Attempting to call the `ray` instance directly after getting it from `raySetup()` without accessing its `.value` property.fixRemember that `raySetup()` returns a Vue `Ref`. Access the debugging function via `ray.value()`, e.g., `ray.value().log('message')`.
Warnings
- breaking Vue 2 support was dropped in `vue-ray` v2.x. This package is now exclusively for Vue 3 applications.
- breaking `vue-ray` v2.x requires Node.js version 18 or higher. Projects running on older Node.js versions will encounter errors.
- breaking `vue-ray` v2.x is now an ESM-first package. Direct `require()` statements for CommonJS environments will fail.
- gotcha When using `raySetup()` in `<script setup>`, the returned `ray` variable is a Vue `Ref`. You must access its `.value` property to call the actual `ray()` debugging function.
- gotcha The `RayPlugin` export was missing in `vue-ray` versions 2.0.1 and 2.0.2, preventing global plugin installation.
Install
-
npm install vue-ray -
yarn add vue-ray -
pnpm add vue-ray
Imports
- RayPlugin
const { RayPlugin } = require('vue-ray');import { RayPlugin } from 'vue-ray'; - raySetup
const { raySetup } = require('vue-ray');import { raySetup } from 'vue-ray'; - ray().log
import { ray } from 'vue-ray'; ray().log('message');const ray = raySetup(); ray.value().log('message');
Quickstart
import { createApp, ref, onMounted } from 'vue';
import App from './App.vue';
import { RayPlugin, raySetup } from 'vue-ray';
// main.ts or main.js
const app = createApp(App);
app.use(RayPlugin, {
port: 23517, // Default Ray app port
host: 'localhost',
interceptErrors: true, // Send Vue errors to Ray
nodeRaySettings: {
interceptConsoleLog: true // Also send console.log messages to Ray
}
});
app.mount('#app');
// src/components/MyComponent.vue (using <script setup>)
<template>
<div>
<h1>{{ msg }}</h1>
<button @click="triggerRay">Send to Ray</button>
</div>
</template>
<script setup lang="ts">
const msg = ref('Hello Vue Ray!');
const ray = raySetup({
lifecycleEvents: {
created: true, // Send 'created' event to Ray
mounted: true // Send 'mounted' event to Ray
}
});
onMounted(() => {
// Access the ray function via ray.value()
ray.value().log('MyComponent mounted!').data({ message: msg.value });
});
function triggerRay() {
ray.value().html('<i>Button clicked from component!</i>').label('interaction');
try {
// Simulate an error
throw new Error('Example error from component!');
} catch (e: any) {
// If interceptErrors is true in plugin, this will go to Ray automatically
// You can also manually send it:
ray.value().exception(e);
}
}
</script>