tradle / rn-nodeify

hack to allow react-native projects to use node core modules, and npm modules that use them
MIT License
618 stars 112 forks source link

RN 0.62.0 Compatibility (cause duplicate symbols about multiple copy of CocoaAsyncSocket) #94

Open vergil-zhao opened 4 years ago

vergil-zhao commented 4 years ago

Hi,

The version of tradle/react-native-udp has been updated to 3.1.0 but it's still using ^2.1.0 after run ./node_modules/.bin/rn-nodeify --hack --install --yarn.

The same problem is also with react-native-tcp. Since it has been deprecated, it will cause the duplicate symbol issue as well (like #93). I guess it should be replaced by any active module like react-native-tcp-socket (by @Rapsssito).

The older versions of react-native-udp and react-native-tcp both contain a copy of CocoaAsyncSocket or CocoaAsyncUdpSocket which are already introduced by RN per se. New versions are using them as pod dependency to solve the problem.

After I changed them manually, the iOS project can be compiled without errors.

BUT, it will cause runtime issues, like:

Unable to resolve module `stream` from `node_modules/cipher-base/index.js`: stream could not be found within the project.
Unable to resolve module `crypto` from `node_modules/sjcl/sjcl.js`: crypto could not be found within the project.
...

Any idea about this?

Solution

Add this to metro.config.js

resolver: {
    extraNodeModules: {
        crypto: require.resolve('crypto-browserify'),
        stream: require.resolve('stream-browserify'),
        ...
    },
},

Also, any alternative lib can be added this way.