node-deep-extend icon indicating copy to clipboard operation
node-deep-extend copied to clipboard

react-native Buffer is not defined

Open tjbenton opened this issue 7 years ago • 3 comments

When trying to use this library with react-native it throws the following error saying Buffer is not defined.

screen shot 2018-06-20 at 9 49 45 am

I know I can install buffer as a dependency but I would like to avoid adding another dependency to my project when we aren't using Buffer at all.

I resolved the error by adding the following to my code before I used deepExtend.

global.Buffer = global.Buffer || class Buffer {}

if you actually need the functionality for another library, install buffer as a dependency

global.Buffer = global.Buffer || require('buffer').Buffer

tjbenton avatar Jun 20 '18 13:06 tjbenton

this also affects client side code that doesn't have the Buffer polyfill. this recently caused issues in https://github.com/uber/streetscape.gl/pull/167

the fix should just be to check for buffer existing using typeof Buffer !== 'undefined' before using Buffer

vicapow avatar Dec 04 '18 23:12 vicapow

looks liked, based on https://github.com/unclechu/node-deep-extend/pull/27 This module is not actively maintained

vicapow avatar Dec 04 '18 23:12 vicapow

Was wondering about this. Will switch to lodash.merge instead

ardok avatar Feb 12 '19 00:02 ardok