{"id":15725,"library":"node-libs-react-native","title":"Node.js Core Modules for React Native","description":"This package, `node-libs-react-native`, provides React Native compatible implementations of various Node.js core modules such as `stream`, `http`, `buffer`, and `process`. It serves as a fork of `node-libs-browser`, specifically adapted for the React Native environment by swapping certain underlying packages for better mobile compatibility. The primary mechanism involves exposing a mapping of Node module names to their absolute React Native compatible file paths. This mapping is then leveraged within React Native Packager's `metro.config.js` resolver or Webpack's `resolve.alias` configuration to correctly resolve module imports within a React Native project. Additionally, it offers a dedicated `globals` module designed to shim Node.js specific global variables like `Buffer` and `process` into the React Native runtime. The current stable version, 1.2.1, was last published over five years ago, indicating that the project is likely abandoned. Given the rapid evolution of both Node.js and React Native, its utility in modern projects is limited, and more actively maintained alternatives or specific polyfills are generally recommended.","status":"abandoned","version":"1.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/parshap/node-libs-react-native","tags":["javascript"],"install":[{"cmd":"npm install node-libs-react-native","lang":"bash","label":"npm"},{"cmd":"yarn add node-libs-react-native","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-libs-react-native","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primarily used as a CommonJS require in build configuration files like metro.config.js. It exports an object mapping module names to paths. Direct ESM import is not the intended usage for this specific export.","wrong":"import extraNodeModules from 'node-libs-react-native';","symbol":"extraNodeModules","correct":"const extraNodeModules = require('node-libs-react-native');"},{"note":"This is a side-effect import intended to run early in the application lifecycle to polyfill Node.js globals. CommonJS `require` is shown in the documentation and is the canonical way to ensure it runs immediately.","wrong":"import 'node-libs-react-native/globals';","symbol":"globals shim","correct":"require('node-libs-react-native/globals');"}],"quickstart":{"code":"// metro.config.js\nmodule.exports = {\n  resolver: {\n    // This configuration instructs Metro to resolve Node.js core modules\n    // using the React Native compatible implementations provided by the package.\n    extraNodeModules: require('node-libs-react-native'),\n  },\n  // It's also common to need a custom assetExts array\n  // if you're importing assets not natively supported by React Native,\n  // though not directly related to node-libs-react-native.\n  // transformer: {\n  //   getTransformOptions: async () => ({\n  //     transform: {\n  //       experimentalImportSupport: false,\n  //       inlineRequires: true,\n  //     },\n  //   }),\n  // },\n};","lang":"javascript","description":"Configures the Metro bundler resolver to provide React Native compatible Node.js core modules."},"warnings":[{"fix":"Consider migrating to actively maintained alternatives or specific polyfills for individual Node.js modules if needed. A community-maintained fork like `@pagopa/react-native-nodelibs` might offer better compatibility with newer React Native versions.","message":"The package is largely unmaintained, with the last update over five years ago (version 1.2.1). It may not be compatible with recent versions of React Native or Node.js, leading to build failures or runtime errors.","severity":"breaking","affected_versions":">=1.2.2 (hypothetical), or any version with modern React Native"},{"fix":"Thoroughly test any Node.js module functionality used within React Native. Avoid relying on complex or less common features that might not be correctly polyfilled. Explicitly check the provided module list in the documentation for supported modules and their limitations.","message":"Shimming Node.js core modules in a non-Node environment like React Native can introduce subtle behavioral differences or incomplete implementations. Not all Node.js APIs or module features are fully replicated.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Add `require('node-libs-react-native/globals');` as one of the very first lines in your application's main entry file (e.g., `index.js` or `App.js`) to ensure these globals are available before other modules might try to access them.","message":"The package does not automatically provide Node.js global variables like `Buffer` or `process`. These must be explicitly shimmed by importing `node-libs-react-native/globals` early in your application's entry point.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Before using a Node.js core module, consult the `Modules` table in the package's documentation to confirm if it's supported. For unsupported modules, seek React Native-specific libraries (e.g., `react-native-fs` for file system operations) or re-evaluate the architectural need for that module.","message":"Some Node.js core modules, such as `fs` (file system), `child_process`, `cluster`, `dgram`, `module`, `net`, `readline`, `repl`, and `tls`, are not provided or are explicitly marked as unsupported/mocked with minimal functionality in this package. Relying on them will fail at runtime.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure your `metro.config.js` file is correctly set up with `resolver.extraNodeModules: require('node-libs-react-native')`. Restart your Metro bundler after making changes to the config.","cause":"A React Native module is trying to import a Node.js core module (e.g., `stream`, `http`, `crypto`) that Metro is not configured to resolve.","error":"Error: Unable to resolve module `stream` from `...`. Module does not exist in the Haste module map."},{"fix":"Add `require('node-libs-react-native/globals');` to the very top of your application's entry file (e.g., `index.js`). This shims the `Buffer` and `process` globals into the React Native environment.","cause":"Your React Native application or one of its dependencies is attempting to use the `Buffer` global object, which is a Node.js specific global, without it being polyfilled.","error":"ReferenceError: Buffer is not defined"}],"ecosystem":"npm"}