parshap/node-libs-react-native

Buffer is not defined

Closed this issue · 4 comments

Hi,

When I try to import the stream module I see the problem: Buffer is not defined

My environment is React Native 0.55
How can I solve that?

For example, I have done like that but It didn't help me.

import {Buffer} from 'buffer'; global.Buffer = Buffer; import stream from 'stream';

What error do you get? Did you follow the "Globals" section of the readme to add require('node-libs-react-native/globals'))?

umpc commented

Hello,

I got this error after following the readme.

I fixed this issue by switching from import to require on the dependency that needed Buffer.

Mixing import and require() can have unexpected results -- import statements are hoisted above require(). People seem to run into this often (see #4), this should get noted in the readme and the examples should all use import instead of require() since that's most common in the wild.

Closing this, because it seems to be a dupe of #4. Please reopen if still relevant.