I'm currently attempting to take advantage of bitcoinjs-lib in a react native project, but receiving the following error upon build, "Can't find variable: Buffer"

@coreyphillips can you paste stacktrace?

I haven't used React Native yet, but it's my understanding Node core modules aren't supported. This project may help you hack them in: https://github.com/mvayngrib/rn-nodeify
Try ensuring that https://github.com/feross/buffer is in the namespace, and if not insert it yourself.
Otherwise, as @jprichardson said.
Thanks for the suggestions. Unfortunately, rn-nodeify and manually inserting Buffer into the namespace were not effective. @jprichardson, I believe you are correct. React Native is reluctant to work with some node modules at the moment. I will continue to look into this in an effort to get bitcoinjs-lib up and running in react native. I'll post a workaround or update when able.
Update: I'm one small step closer to getting bitcoinjs-lib up and running in React Native. @jprichardson, rn-nodeify did in fact mostly work, I simply implemented it wrong. I ended up using this example to help properly implement it (https://github.com/mvayngrib/adexample).
I'm now receiving the following error in the iOS simulator:
"secure random number generation not supported by this browser use chrome, Firefox or Internet Explorer 11"
It appears to be coming from ecpair.js on line 88.

I haven't been able to test this on Android yet, but I'm looking for ways around the rng(32) error on iOS.
@coreyphillips https://github.com/crypto-browserify/randombytes/blob/master/browser.js#L4
This means your JS engine doesn't have a crypto.getRandomValues implementation.
You'll have to rectify this with your own RNG function (taking a n size parameter), passed in via options.rng.
e.g
function myRng (n) {
var buf = new Buffer(n)
buf.fill(4) // so random! :P
return buf
}
That's it! Thanks @dcousens. I've provided some documentation below that covers the creation of the react native project to implementing bitcoinjs-lib for anyone else that comes across this issue.
//In the terminal
react-native init myBitcoinProject
cd myBitcoinProject
npm i
npm i -S bitcoinjs-lib asyncstorage-down assert
npm i -D rn-nodeify
//Add the following to the scripts tag in your package.json file
"postinstall": "./node_modules/.bin/rn-nodeify --install buffer,events,process,stream,util,inherits,fs,path --hack"
//In the terminal
npm i
//Require the following two lines to your .js file
require('./shim');
var bitcoin = require('bitcoinjs-lib');
//Open ecpair.js in ./node_modules/bitcoinjs-lib/src/ecpair.js and add the following to ECPair.makeRandom:
function myRng (n) {
var buf = new Buffer(n)
var num = Math.floor((Math.random() * (2500000000 * 10)) + 1) //Demo purposes only
buf.fill(num)
return buf
}
//And replace line 88 or (var buffer = rng(32)) with your new function:
var buffer = myRng(32)
var num = Math.floor((Math.random() * (2500000000 * 10)) + 1) //Demo purposes only
I know it is "demo purposes only", but some people won't realise that this is a catastrophically bad idea.
Please only use a safe random number source.
Also, @coreyphillips, you should just do:
ECPair.makeRandom({
rng: myRng
})
No need to edit the library code.
@coreyphillips @dcousens
This means your JS engine doesn't have a crypto.getRandomValues implementation.
You'll have to rectify this with your own RNG function (taking a n size parameter), passed in via options.rng.
Very weird. iOS 9.2 (Webkit) supports crypto.getRandomValues....
Must be a React-Native or rn-nodeify... pinging @mvayngrib for his thoughts...
@coreyphillips maybe reopen this issue in rn-nodeify, it's not really a bitcoinjs-lib problem. The sync random number generator issue is a react-native-randombytes 1.x.x limitation, starting with 2.x.x it's supported.
Thanks @mvayngrib :+1:
Closing :)
Most helpful comment
That's it! Thanks @dcousens. I've provided some documentation below that covers the creation of the react native project to implementing bitcoinjs-lib for anyone else that comes across this issue.