Flipper Common Utilities
flipper-common is a core utility package within the Facebook Flipper debugging platform, designed to provide shared functionalities and interfaces for `flipper-ui`, `flipper-server`, and Flipper plugins. It encapsulates common logic and types used across different components of the Flipper ecosystem, ensuring consistency and reducing code duplication. The package is currently at version 0.273.0 and maintains a rapid release cadence, often seeing multiple updates per month to align with the active development of the broader Flipper project. Its key differentiators lie in its deep integration within the Flipper architecture, serving as a foundational layer for building robust mobile (iOS/Android) and web/Node.js debugging plugins and server-side interactions, rather than being a general-purpose, standalone utility library.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'Logger')
cause Attempting to `require()` named exports from 'flipper-common' in a CommonJS environment, which primarily ships as ES Modules.fixEnsure your project is configured for ES Modules (e.g., `"type": "module"` in `package.json` or using `.mjs` files) and use `import { Logger } from 'flipper-common';` syntax. If truly stuck in CommonJS, you might need dynamic `import()` or a bundler to transpile. -
Error: Package subpath './lib/Logger' is not defined by 'exports' in .../node_modules/flipper-common/package.json
cause Directly importing internal subpaths of the `flipper-common` package that are not exposed via its `exports` field in `package.json`.fixAlways import symbols directly from the main package entry point: `import { Logger } from 'flipper-common';`. Do not attempt to import from `flipper-common/lib/Logger` or similar internal paths. -
TS2305: Module ''flipper-common'' has no exported member 'SomeNonExistentType'.
cause Trying to import a type or function that does not exist or is not publicly exported by `flipper-common`.fixConsult the official Flipper documentation or the package's type definitions (`.d.ts` files) to verify the correct names and availability of exported members. Flipper's internal nature means not all internal types or functions are exposed publicly.
Warnings
- breaking As `flipper-common` is versioned `0.x.x` and part of a rapidly evolving internal Facebook project, breaking changes can be introduced in minor version increments. Always consult the detailed Flipper `CHANGELOG.md` (linked in npm metadata) when upgrading to a new minor version.
- gotcha This `flipper-common` package is part of the Facebook Flipper debugging platform for mobile and web applications, not related to the Flipper Zero hardware device. Attempting to use these utilities for Flipper Zero development will result in incompatibility.
Install
-
npm install flipper-common -
yarn add flipper-common -
pnpm add flipper-common
Imports
- Logger
const Logger = require('flipper-common');import { Logger } from 'flipper-common'; - Id
import Id from 'flipper-common'; // Id is a named export, not default
import { Id } from 'flipper-common'; - FlipperClient
import { FlipperClient } from 'flipper-common'; // FlipperClient is a type, not a runtime valueimport type { FlipperClient } from 'flipper-common';
Quickstart
import { Logger, Id, FlipperClient } from 'flipper-common';
interface MyPluginClient extends FlipperClient {
sendEvent: (event: string, payload: any) => void;
}
class MyFlipperPlugin {
id: Id;
logger: Logger;
client: MyPluginClient;
constructor(client: MyPluginClient) {
this.id = new Id();
this.logger = new Logger('MyFlipperPlugin');
this.client = client;
this.logger.info(`Plugin initialized with ID: ${this.id.newID()}`);
}
initiateConnection() {
this.client.sendEvent('plugin-connected', { pluginName: 'MyFlipperPlugin', version: '1.0.0' });
this.logger.debug('Sent connection event to Flipper desktop.');
}
// Example of using another utility or type
processData(data: any) {
const transactionId = this.id.newID();
this.logger.verbose(`Processing data with transaction ID: ${transactionId}`);
// Imagine further processing or sending data back via client
this.client.sendEvent('data-processed', { id: transactionId, result: data });
}
}
// Simulate a Flipper client for demonstration
const mockFlipperClient: MyPluginClient = {
sendEvent: (event, payload) => {
console.log(`[Mock Flipper Client] Event: ${event}, Payload: ${JSON.stringify(payload)}`);
},
// In a real FlipperClient, there would be more methods like 'onMessage', 'call', etc.
// These are omitted for a minimal runnable example.
};
const plugin = new MyFlipperPlugin(mockFlipperClient);
plugin.initiateConnection();
plugin.processData({ value: 123, status: 'complete' });