Registry / crm-productivity / launchdarkly-vue-client-sdk

launchdarkly-vue-client-sdk

JSON →
library2.5.0jsnpmunverified

The LaunchDarkly Vue Client SDK provides seamless integration of feature flags into Vue.js applications, specifically supporting Vue 3.2 and newer versions. As of `2.5.0`, it offers a robust solution for dynamically managing features, building upon the core LaunchDarkly JavaScript SDK. Key differentiators include first-class support for Vue's Composition API through reactive hooks (like `useFlags` and `useLDClient`) and a dedicated Vue plugin for easy initialization. The SDK sees frequent releases, typically every 1-3 months, ensuring compatibility with the latest Vue and LaunchDarkly platform features. It is designed for client-side environments, requiring a client-side ID for authentication and specific flag configurations to ensure availability.

npm install launchdarkly-vue-client-sdk
INSTALL
IMPORT
SIG · LAUNCHDARKLY-VUE-C
L
launchdarkly-vue-client-sdk
crm-productivityjavascriptv2.5.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LDPlugin
import { LDPlugin } from 'launchdarkly-vue-client-sdk'
import LaunchDarklyVue from 'launchdarkly-vue-client-sdk'
The official documentation indicates `LDPlugin` for direct import and use with `app.use()`. Some older examples or community articles might refer to `LaunchDarklyVue` as a default export, but `LDPlugin` is the canonical named export for the plugin itself.
useFlags
import { useFlags } from 'launchdarkly-vue-client-sdk'
Provides all feature flags for the current context as a reactive object, typically used within Vue's Composition API `setup` hook or `<script setup>`.
useLDClient
import { useLDClient } from 'launchdarkly-vue-client-sdk'
Provides direct access to the underlying LaunchDarkly JavaScript client instance, allowing for more advanced interactions like `track` or `identify`. Must be used within Vue's Composition API `setup` hook or `<script setup>`.
useLDFlag
import { useLDFlag } from 'launchdarkly-vue-client-sdk'
Provides a single feature flag's value as a reactive `ref`, allowing for fine-grained reactivity and automatic re-rendering upon flag changes. It is recommended for accessing individual flags.
LDContext
import { LDContext } from 'launchdarkly-vue-client-sdk'
Type definition for a LaunchDarkly context object, re-exported for convenience from the underlying JavaScript SDK. Essential for strongly typing context definitions.

This quickstart demonstrates how to initialize the LaunchDarkly Vue SDK using `LDPlugin`, configure an `LDContext`, and then consume a feature flag reactively within a Vue component using the `useLDFlag` composable. It also shows how to access the underlying `LDClient` for custom event tracking.

import { createApp } from 'vue'; import App from './App.vue'; import { LDPlugin, LDContext, useLDFlag } from 'launchdarkly-vue-client-sdk'; // It's best practice to load your client-side ID from environment variables. // For Vite, use import.meta.env.VITE_LD_CLIENT_SIDE_ID // For other bundlers or Node.js, use process.env.LD_CLIENT_SIDE_ID const clientSideId = process.env.VITE_LD_CLIENT_SIDE_ID ?? 'YOUR_CLIENT_SIDE_ID'; // Replace with your actual Client-side ID const context: LDContext = { kind: 'user', key: 'example-user-key', name: 'Example User', // Custom attributes can be added here _meta: { privateAttributes: ['email'] }, // Example: Mark 'email' as private }; const app = createApp(App); // Initialize the LaunchDarkly Vue plugin app.use(LDPlugin, { clientSideId, context, // Optional: Add further options for the underlying JS SDK options: { streaming: true, // Enables real-time flag updates // logger: LaunchDarkly.basicLogger({ level: 'debug' }), // Uncomment for debug logs }, }); app.mount('#app'); // App.vue <script setup lang="ts"> import { ref, watchEffect } from 'vue'; import { useLDClient, useLDFlag } from 'launchdarkly-vue-client-sdk'; // Use useLDFlag for a specific flag, providing a fallback value const myFeatureEnabled = useLDFlag('my-boolean-feature', false); // Access the underlying LDClient for advanced operations like tracking events const ldClient = useLDClient(); const trackCustomEvent = () => { if (ldClient) { ldClient.track('button-clicked', { customData: 'from-vue' }); console.log('Custom event tracked!'); } }; </script> <template> <div> <h1>LaunchDarkly Vue SDK Demo</h1> <p>Is 'my-boolean-feature' enabled? <strong>{{ myFeatureEnabled ? 'Yes' : 'No' }}</strong></p> <button @click="trackCustomEvent">Track Button Click</button> <p v-if="myFeatureEnabled">This content is only visible if 'my-boolean-feature' is ON!</p> <p v-else>This content is visible if 'my-boolean-feature' is OFF!</p> </div> </template>
Debug
Known issues
gotchaThe SDK requires a 'Client-side ID' for initialization, not an 'SDK key' or 'Mobile key'. Using an incorrect key type (e.g., a server-side SDK key) will prevent the client from initializing correctly and could lead to unexpected behavior or security issues.
fix
Ensure you are using the 'Client-side ID' found in your LaunchDarkly project settings. Do not embed a server-side SDK key in client-side code.
affects: >=2.0.0
gotchaFor any feature flag to be available to the Vue SDK, the 'Make this flag available to client-side SDKs' checkbox must be enabled on that flag's settings page in the LaunchDarkly dashboard. If not enabled, the SDK will receive the flag's fallback value.
fix
Navigate to the flag's settings in the LaunchDarkly UI and ensure the 'Make this flag available to client-side SDKs' option is checked.
affects: >=2.0.0
breakingThe `waitForInitialization` method's behavior changed in version 2.2.0. If a timeout is specified, the returned promise will now be rejected after the timeout elapses if the client has not finished initializing. Previously, it would only resolve or reject upon completion or failure without a timeout.
fix
Update error handling for `waitForInitialization` to catch promise rejections if you are using a timeout. If no timeout is specified, the promise still waits indefinitely.
affects: >=2.2.0
breakingThe `track` method now validates that the `metricValue` parameter is a number since version 2.2.0. If a non-numeric value is provided for `metricValue`, a warning will be logged, and the event might not be tracked as expected.
fix
Ensure that any `metricValue` passed to the `track` method is a valid number. For non-numeric custom data, pass it within the `data` object of the event properties.
affects: >=2.2.0
breakingThis SDK exclusively supports Vue 3.2 and newer versions. Attempts to use it with Vue 2.x projects will result in compatibility errors and unexpected behavior.
fix
Upgrade your Vue project to Vue 3.2 or later. For Vue 2 projects, consider using the LaunchDarkly JavaScript SDK directly or community-developed wrappers compatible with Vue 2.
affects: >=2.0.0
breakingStarting with version 2.0.0, the SDK only operates on 'contexts' instead of 'users'. Any existing code from 1.x versions that used `LDUser` must be updated to use `LDContext`. While the underlying JS SDK might convert `LDUser` to `LDContext` implicitly, it's strongly recommended to explicitly use `LDContext` for correct behavior and full feature access.
fix
Replace all instances of `LDUser` with `LDContext` when defining your entities for flag evaluation. Ensure your context object explicitly defines a `kind` attribute.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: app.use is not a function
Attempting to use the SDK's Vue plugin with a Vue 2 application or an improperly created Vue 3 app instance.
fix
Ensure your project is running Vue 3.2 or newer and that `app` is a valid Vue 3 application instance created with `createApp()`.
LaunchDarkly client not initialized or flag not found (fallback value returned unexpectedly).
The LaunchDarkly client failed to initialize due to an invalid `clientSideId`, or the specific feature flag is not enabled for client-side SDKs in the LaunchDarkly dashboard.
fix
Verify that the `clientSideId` passed to `LDPlugin` is your correct LaunchDarkly Client-side ID (not an SDK key). Also, confirm that the feature flag in question has the 'Make this flag available to client-side SDKs' option checked in your LaunchDarkly dashboard.
Property 'email' does not exist on type 'LDContext'.
Attempting to access a specific attribute like 'email' directly on a generic `LDContext` type without specifying its structure or `kind` property in TypeScript.
fix
When defining your `LDContext`, ensure you explicitly specify custom attributes or use type assertions if your context has a known structure. For example: `{ kind: 'user', key: 'example', email: 'test@example.com' } as LDContext & { email: string }`.
Error: useLDFlag must be called from within a setup function or script setup.
The `useLDFlag` (or other `useLD...` composables) is being called outside of a Vue Composition API `setup` function or a `<script setup>` block.
fix
Ensure all LaunchDarkly composables (`useLDFlag`, `useFlags`, `useLDClient`, etc.) are invoked directly within the `<script setup>` block of a Vue component or inside the `setup()` method of an options API component.
Upgrade
Version history
2.5.0latest on npm
Audit
Dependencies
vuerequiredPeer dependency for core Vue.js functionality.
Agent activity
27 hits · last 30 days
node
24
OpenAI (training)
1
Resources
launchdarkly-vue-client-sdk — npm install launchdarkly-vue-client-sdk · libregistry