Registry / devops / launchdarkly-js-client-sdk

launchdarkly-js-client-sdk

JSON →
library3.9.1jsnpmunverified

The `launchdarkly-js-client-sdk` package provides client-side feature flag management for JavaScript applications running in web browsers. It allows developers to control features remotely without redeploying code, enabling practices like A/B testing, gradual rollouts, and kill switches. This specific package is currently at version 3.9.1 but is officially deprecated. All future development and releases are now happening under the `@launchdarkly/js-client-sdk` monorepo package. It leverages the 'Client-side ID' for authentication and requires flags to be explicitly made available to client-side SDKs. Release cadence was previously frequent for this package, but it is now in maintenance mode, with new features directed to the new package. Its primary differentiator is robust feature flag management with detailed event tracking and a strong focus on enterprise features, often used in conjunction with React through the `react-client-sdk` addon.

npm install launchdarkly-js-client-sdk
INSTALL
IMPORT
SIG · LAUNCHDARKLY-JS-CL
L
launchdarkly-js-client-sdk
devopsjavascriptv3.9.1
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.

initialize
import { initialize } from 'launchdarkly-js-client-sdk';
const initialize = require('launchdarkly-js-client-sdk').initialize;
The `initialize` function is the primary entry point for the SDK, returning an `LDClient` instance. While CommonJS `require` works, ESM `import` is the recommended modern approach for browser-based JavaScript.
LDClient
import { LDClient } from 'launchdarkly-js-client-sdk';
import LDClient from 'launchdarkly-js-client-sdk';
The `LDClient` class (or its type) is returned by the `initialize` function. It's a named export, not a default export. You typically obtain an instance from `initialize` rather than creating it directly.
LDUser
import { LDUser } from 'launchdarkly-js-client-sdk';
import { User } from 'launchdarkly-js-client-sdk';
The `LDUser` interface defines the structure for user context objects passed during initialization and for flag evaluations. It's a named type export.

Initializes the LaunchDarkly client for a given user, evaluates a boolean feature flag, and tracks a custom event, logging results to the console.

import { initialize, LDUser, LDClient, LDOptions } from 'launchdarkly-js-client-sdk'; // Replace with your actual Client-side ID from LaunchDarkly project settings const LAUNCHDARKLY_CLIENT_SIDE_ID = process.env.LAUNCHDARKLY_CLIENT_SIDE_ID ?? 'YOUR_CLIENT_SIDE_ID'; // Define a user context. The 'key' is mandatory. const user: LDUser = { key: 'example-user-key', name: 'Example User', email: 'user@example.com', custom: { region: 'us-west' } }; // Define SDK options (optional, here enabling debug logging) const options: LDOptions = { debug: true, }; // Initialize the LaunchDarkly client const ldClient: LDClient = initialize(LAUNCHDARKLY_CLIENT_SIDE_ID, user, options); ldClient.on('ready', () => { console.log('LaunchDarkly client is ready!'); // Evaluate a boolean feature flag with a default value of `false` const showNewFeature = ldClient.variation('new-feature-flag', false); if (showNewFeature) { console.log('The new feature is ENABLED for this user!'); } else { console.log('The new feature is DISABLED for this user.'); } // Track a custom event for analytics ldClient.track('button-click', { buttonId: 'submit-form' }); }); ldClient.on('failed', (error) => { console.error('LaunchDarkly initialization failed:', error); }); // In a real application, you might export ldClient or make it globally available // for other parts of your application to use.
Debug
Known issues
breakingThis `launchdarkly-js-client-sdk` package is officially deprecated. All future development, bug fixes, and new features will be released under the new monorepo package `@launchdarkly/js-client-sdk`. Users are strongly encouraged to migrate.
fix
Migrate your project to use the `@launchdarkly/js-client-sdk` package. Refer to the official LaunchDarkly documentation and migration guides for the new package.
affects: >=3.9.1
gotchaThe SDK requires a 'Client-side ID' from your LaunchDarkly account settings, not the 'SDK key' or 'Mobile key'. Using the incorrect key will prevent the client from initializing and fetching flags.
fix
Verify that you are using the correct 'Client-side ID' found in your LaunchDarkly project's environment settings. It typically starts with '5...'.
affects: >=1.0.0
gotchaFor any feature flag to be accessible in the client-side SDK, the 'Make this flag available to client-side SDKs' checkbox must be enabled on the flag's settings page in the LaunchDarkly dashboard.
fix
Check the settings for any feature flags you intend to use with this SDK and ensure the client-side availability option is enabled.
affects: >=1.0.0
gotchaOlder browser environments may lack native support for features like `Promise`, `EventSource`, or `document.querySelectorAll()`, which are used by the SDK. This can lead to runtime errors or silent failures.
fix
Include appropriate polyfills (e.g., `core-js`, `whatwg-fetch`) in your application bundle if you need to support older browsers. Consult the LaunchDarkly documentation on 'JS SDK requirements and polyfills'.
affects: >=1.0.0
gotchaThe `waitForInitialization` method, if called without a timeout, will await indefinitely if the client fails to initialize (e.g., due to network issues or incorrect configuration) without an explicit error handler or rejection.
fix
Consider adding an optional timeout parameter to `waitForInitialization` (e.g., `ldClient.waitForInitialization(5000)`) to ensure that the promise eventually resolves or rejects, preventing indefinite blocking.
affects: >=3.3.0
Errors
Common errors & fixes
LaunchDarkly client did not initialize. Please check your SDK key and network connection.
Incorrect Client-side ID, network connectivity issues, or firewall blocking access to LaunchDarkly servers.
fix
Double-check the provided Client-side ID against your LaunchDarkly project settings. Ensure your client device has active internet access and is not being blocked by a firewall or proxy from reaching LaunchDarkly endpoints.
ReferenceError: Promise is not defined
The browser environment does not natively support the `Promise` object, and no polyfill has been included.
fix
Add a `Promise` polyfill (e.g., from `core-js` or `es6-promise`) to your application bundle to ensure compatibility with older browsers.
TypeError: ldClient.variation is not a function
Attempting to call `variation` on an `ldClient` instance that has not yet completed initialization or is undefined due to initialization failure.
fix
Ensure you call `ldClient.variation` only after the `ready` event fires or `waitForInitialization()` resolves, indicating the client is ready to provide flag values. Handle potential initialization failures gracefully.
Upgrade
Version history
3.9.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Bingbot
1
OpenAI (training)
1
Resources