{"id":10878,"library":"fbjs","title":"FBJS Utilities","description":"FBJS (Facebook JavaScript) is a collection of utility libraries developed by Facebook primarily for internal consumption within their JavaScript projects, such as React and Relay. Currently at version 3.0.5, this package does not follow strict semantic versioning and APIs may change or disappear without public notice. It is explicitly not designed for broader public use, and external projects consuming it should anticipate instability and a lack of support. Its core purpose is to facilitate code sharing across Facebook's internal monorepo, leveraging a custom `@providesModule` system that is transformed into CommonJS `require('fbjs/lib/moduleName')` paths during a build step. There is no stated public release cadence, as its releases are tied directly to Facebook's internal development needs.","status":"maintenance","version":"3.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/facebook/fbjs","tags":["javascript"],"install":[{"cmd":"npm install fbjs","lang":"bash","label":"npm"},{"cmd":"yarn add fbjs","lang":"bash","label":"yarn"},{"cmd":"pnpm add fbjs","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"FBJS primarily ships as CommonJS. The `import` syntax will typically fail without specific build tooling or will result in incorrect interop behavior. Always use `require` for FBJS utilities.","wrong":"import { emptyFunction } from 'fbjs/lib/emptyFunction';","symbol":"emptyFunction","correct":"const emptyFunction = require('fbjs/lib/emptyFunction');"},{"note":"The `warning` utility is a named export within its module. Attempting a default import or incorrect named ESM import will fail.","wrong":"import warning from 'fbjs/lib/warning';","symbol":"warning","correct":"const warning = require('fbjs/lib/warning');"},{"note":"Like other FBJS utilities, `invariant` is a CommonJS module exported from a specific path. The root `fbjs` package does not directly export these utilities.","wrong":"import { invariant } from 'fbjs';","symbol":"invariant","correct":"const invariant = require('fbjs/lib/invariant');"}],"quickstart":{"code":"// This example demonstrates direct CommonJS usage of FBJS utilities.\n// Note: FBJS is primarily intended for internal Facebook projects and\n// is not guaranteed to follow semver or provide stable public APIs.\n\nconst emptyFunction = require('fbjs/lib/emptyFunction');\nconst warning = require('fbjs/lib/warning');\nconst invariant = require('fbjs/lib/invariant');\nconst identity = require('fbjs/lib/identity');\n\nconsole.log('Calling emptyFunction:', emptyFunction()); // Should print undefined\n\nlet shouldWarn = true;\nwarning(\n  !shouldWarn, // Condition for warning to trigger (true means no warning, false means warning)\n  'This is a development warning from FBJS. Condition was %s.', // Message\n  shouldWarn // Args for message formatting\n);\n\n// invariant example (will throw if condition is false)\ntry {\n  const value = null;\n  invariant(value != null, 'Value must not be null or undefined.');\n  console.log('Value is:', value);\n} catch (e) {\n  console.error('Invariant failed:', e.message);\n}\n\nconsole.log('Identity of 123 is:', identity(123)); // Should print 123","lang":"javascript","description":"Demonstrates direct CommonJS `require` usage of core FBJS utilities like `emptyFunction`, `warning`, `invariant`, and `identity`, illustrating their typical functionality."},"warnings":[{"fix":"Avoid using FBJS directly in non-Facebook projects. If absolutely necessary, pin exact versions and be prepared for frequent manual updates and compatibility checks.","message":"FBJS is not intended for public consumption and does not adhere to semantic versioning (semver). APIs may change, break, or be removed without notice, leading to frequent breaking changes in patch or minor versions.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Consider implementing similar utilities yourself or finding widely-supported alternatives if you require external support or stable APIs.","message":"Official support and feature requests for FBJS are limited to internal Facebook projects. External projects will not receive support for issues or new features.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your build system correctly applies the FBJS Babel transforms, or explicitly `require('fbjs/lib/moduleName')` for specific utilities. However, direct external usage is strongly discouraged.","message":"FBJS heavily relies on a custom `@providesModule` system and Babel transforms (like `babel-preset/plugins/rewrite-modules.js`) to resolve module paths. Without this specific build setup, direct `require()` calls to relative paths like `emptyFunction` will fail.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure your Babel configuration includes the FBJS `rewrite-modules` plugin, or explicitly `require('fbjs/lib/emptyFunction')`. However, external use is not recommended.","cause":"Your build system is not configured to resolve `@providesModule` references from FBJS, or you are trying to use a non-existent module.","error":"Cannot find module 'emptyFunction'"},{"fix":"Use CommonJS `const warning = require('fbjs/lib/warning');` pattern, as FBJS primarily ships as CommonJS. Avoid ESM imports unless specifically compiled to work with FBJS.","cause":"Attempting to use a named export (like `warning`) as a default import in an ESM context, or incorrect interop with CommonJS modules.","error":"TypeError: (0 , _warning.default) is not a function"},{"fix":"Review the conditions leading to the invariant call and ensure all preconditions for the operation are satisfied before calling the FBJS utility.","cause":"An `invariant` check failed, meaning a critical condition expected by the FBJS utility (or the calling code) was not met.","error":"Invariant Violation: Value must not be null or undefined."}],"ecosystem":"npm"}