{"id":13837695,"url":"https://github.com/tradle/rn-nodeify","last_synced_at":"2025-08-02T12:07:55.248Z","repository":{"id":2093141,"uuid":"40018465","full_name":"tradle/rn-nodeify","owner":"tradle","description":"hack to allow react-native projects to use node core modules, and npm modules that use them","archived":false,"fork":false,"pushed_at":"2023-11-21T02:06:59.000Z","size":96,"stargazers_count":623,"open_issues_count":36,"forks_count":112,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-08T14:45:15.386Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tradle.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-07-31T18:11:19.000Z","updated_at":"2025-04-03T00:17:13.000Z","dependencies_parsed_at":"2024-01-13T17:11:13.574Z","dependency_job_id":"aa8222b4-3f60-4797-a937-ac81542cf437","html_url":"https://github.com/tradle/rn-nodeify","commit_stats":{"total_commits":161,"total_committers":23,"mean_commits":7.0,"dds":0.515527950310559,"last_synced_commit":"338d8d6ba8438403093e9409e9a9d88ad884926f"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tradle%2Frn-nodeify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tradle%2Frn-nodeify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tradle%2Frn-nodeify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tradle%2Frn-nodeify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tradle","download_url":"https://codeload.github.com/tradle/rn-nodeify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248981260,"owners_count":21193144,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T15:01:20.750Z","updated_at":"2025-04-14T23:51:53.921Z","avatar_url":"https://github.com/tradle.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# rn-nodeify\n\nRun after npm install and you can use node core modules and npm modules that use them in your React Native app.\n\n## What is solves\n\nIf your project has no non-React-Native dependencies, you don't need this module, and you should just check out ['./shims.js'](./shims.js) for the core node modules to use individually.\n\nHowever, with bigger projects that don't reimplement every wheel from scratch, somewhere in your dependency tree, something uses a core node module. I found myself building this because in my React Native app, I wanted to use [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib), [levelup](https://github.com/Level/levelup), [bittorrent-dht](https://github.com/feross/bittorrent-dht), and lots of fun crypto. If that sounds like you, keep reading.\n\n## What it does\n\n`rn-nodeify --install`\ninstalls shims for core node modules, see ['./shims.js'](./shims.js) for the current mappings. It recurses down `node_modules` and modifies all the `package.json`'s in there to add/update the `browser` and `react-native` fields. It sounds scary because it is. However, it does work.\n\n`rn-nodeify --hack`\nNow that you're scared, I should also mention that there are some package-specific hacks (see ['./pkg-hacks.js'](./pkg-hacks.js)), for when the React Native packager choked on something that Webpack and Browserify swallowed.\n\nIf you're looking for a saner approach, check out [ReactNativify](https://github.com/philikon/ReactNativify). I haven't tested it myself, but I think [philikon](https://github.com/philikon) will be happy to help.\n\n## Usage\n\n```bash\nrn-nodeify \u003coptions\u003e\n```\n\n## Options\n\n```\n--install     install node core shims (default: install all), fix the \"browser\"\n              and \"react-native\" fields in the package.json's of dependencies\n--hack        hack individual packages that are known to make the React Native packager choke\n--yarn        use yarn instead of npm\n```\n\n### Examples\n\n```bash\n# install all shims and run package-specific hacks\nrn-nodeify --install --hack\n```\n\n```bash\n# install specific shims\nrn-nodeify --install \"fs,dgram,process,path,console\"\n```\n\n```bash\n# install specific shims and hack\nrn-nodeify --install \"fs,dgram,process,path,console\" --hack\n```\n\nIt is recommended to add this command to the \"postinstall\" script in your project's package.json\n\n```json\n\"scripts\": {\n  \"start\": \"node node_modules/react-native/local-cli/cli.js start\",\n  \"postinstall\": \"rn-nodeify --install fs,dgram,process,path,console --hack\"\n}\n```\n\nrn-nodeify will create a `shim.js` file in your project root directory. The first line in index.ios.js / index.android.js should be to `import` it (NOT `require` it!)\n\n```js\nimport './shim'\n```\n\nIf you are using the crypto shim, you will need to manually uncomment the line to `require('crypto')` in `shim.js`, this is because as of react-native 0.49, dynamically requiring a library is no longer allowed.\n\nSome shims may require linking libraries, be sure to run `react-native link` after installing new shims if you run into problems.\n\n### Example Apps / Workflows\n\n* the [react-native-crypto](https://github.com/tradle/react-native-crypto) package has an example workflow for using crypto in a React Native app\n* this [example React Native app](https://github.com/mvayngrib/adexample) shows how you can use [levelup](https://github.com/Level/levelup) in React Native\n\n### Example Workflow\n\ncopied from [react-native-crypto](https://github.com/tradle/react-native-crypto)\n\n1. Install and shim\n  ```sh\n  npm i --save react-native-crypto\n  # install peer deps\n  npm i --save react-native-randombytes\n  react-native link react-native-randombytes\n  # install latest rn-nodeify\n  npm i --save-dev rn-nodeify@latest\n  # install node core shims and recursively hack package.json files\n  # in ./node_modules to add/update the \"browser\"/\"react-native\" field with relevant mappings\n  ./node_modules/.bin/rn-nodeify --hack --install\n  ```\n\n2. `rn-nodeify` will create a `shim.js` in the project root directory\n  ```js\n  // index.ios.js or index.android.js\n  // make sure you use `import` and not `require`!\n  import './shim.js'\n  // ...the rest of your code\n  import crypto from 'crypto'\n  // use crypto\n  console.log(crypto.randomBytes(32).toString('hex'))\n  ```\n\n## Please note...\n\n- rn-nodeify won't work with modules that are added using `npm link`.\n- modules that contain a .babelrc will cause problems with the latest react-native version (0.20 at this time), remove them after installation (`rm node_modules/*/.babelrc`)\n- when installing a package from git, the postinstall hook isn't triggered, run it manually instead (`npm run postinstall`)\n- restart the react-native packager after installing a module!\n- removing the packager cache helps as well sometimes (`rm -fr $TMPDIR/react-*`)\n- use `npm@3`. `npm@5` has some issues that cause `node_modules` to disappear. See:\n  - https://github.com/tradle/rn-nodeify/issues/42\n  - https://github.com/infinitered/ignite/issues/1101\n  - https://github.com/npm/npm/issues/16839\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftradle%2Frn-nodeify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftradle%2Frn-nodeify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftradle%2Frn-nodeify/lists"}