React-Native: Can't find variable: Buffer

Viewed 7791

I have a problem with the variable Buffer. You can see it in the image below. Can anybody help me???
Error

Thanks.

2 Answers

So buffer is core Node JS module, which means it’s probably C++ code bundled with the Node JS binary, not Javascript. The React Native packager can’t package it along with your app’s Javascript bundle, so you get a runtime error: Unable to resolve module .

To resolve this issue you need do this to make it run in react-native

npm i --save react-native-randombytes
react-native link react-native-randombytes

# install latest rn-nodeify 
npm i --save-dev tradle/rn-nodeify

# install node core shims and recursively hack package.json files 

 Now you need to run this command in your project directory

./node_modules/.bin/rn-nodeify --hack --install

Final step

import this in your app.js

import './shim.js'

And in packaje.json put this postinstall:./node_modules/.bin/rn-nodeify --hack --install

You probably need to install nodejs buffer. (npm i -S buffer) Also check this answer

Related