Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer is not defined #5

Closed
franleplant opened this issue Mar 23, 2017 · 6 comments
Closed

Buffer is not defined #5

franleplant opened this issue Mar 23, 2017 · 6 comments

Comments

@franleplant
Copy link

Hi! Thanks a lot for your work.

I've followed the guides but I cannot seem to pass the globals error:

  • Buffer is not defined

I did add the globals.js and import it from my code

If I change the order of the globals import, I get something like:

  • cannot inherit from undefined

In any case, I thought i would be nice to at least contribute in this way to your work.
Im actively trying other alternatives to make mqtt work with React Native

@wswoodruff
Copy link

@franleplant Yo! I just ran into this issue as well, and I'm trying to bring it in with various babel global plugins with no luck so far. Have you arrived at an answer yet?

@wswoodruff
Copy link

Hey @franleplant I got this error to go away just by requiring my globals.js file in the file where I register the app.
I do require('../globals.js'); (The main file is in a src/ folder)

globals.js has this in it:

// Inject node globals into React Native global scope.
global.Buffer = require('buffer').Buffer;
global.process = require('process');
global.process.env.NODE_ENV = __DEV__ ? 'development' : 'production';

// Needed so that 'stream-http' chooses the right default protocol.
global.location = {
    protocol: 'file:'
};

You can see a working example here: https://github.com/wswoodruff/strangeluv-native/blob/master/src/index.js#L6

If you have other issues, I ran into problems with crypto.pbkdf2Sync, and made a temporary shim for it until someone comes up with a better solution. You can see #6 and https://github.com/mvayngrib/react-native-crypto/issues/14#issuecomment-306072211 for more info. Please let me know if you get it working!

@franleplant
Copy link
Author

Hey @wswoodruff thank you so much for your contribution. Im not actively working on React Native at the moment and I don't have a dev env for it so I'm not going to be testing this soon, but it's great to have this sort of experience documented for future users (even our future selves). So thank you!

@realflavioc
Copy link

Was having the same issue, this combined with #4 was exactly what I needed, thank you so much @wswoodruff @franleplant @philikon @parshap

@arshbot
Copy link

arshbot commented Jan 24, 2018

Following all the same tools and tactics however I am unable to over this error. It looks like Buffer isn't in the global scope for some reason. Getting Buffer is not defined in a standard library util folder node_modules/core-util-is/lib/util.js on exports.isBuffer = Buffer.isBuffer;

@kpanuragh
Copy link

use this package https://www.npmjs.com/package/react-zlib-js and import buffer from react-zlib-js/buffer adn replace "Buffer" with buffer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants