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.
npm install node-libs-react-nativeVerified import paths — ran on the pinned version, not inferred.
Configures the Metro bundler resolver to provide React Native compatible Node.js core modules.
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.
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.
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.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.
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.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.No dependency data recorded yet.