Can't find variable: Buffer

后端 未结 5 1351
悲&欢浪女
悲&欢浪女 2020-12-16 05:50

I\'m trying to use node modules in my react-native app, and I\'m taking the ReactNativify approach here.

I\'m all set up now, and I got the crypto package to load i

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 06:07

    first install the following

    yarn add buffer process babel-plugin-react-native-nodeify-hack
    

    Then add to your babel settings .babelrc

    {
      "presets": ["react-native"],
      "plugins": ["babel-plugin-react-native-nodeify-hack"]
    }
    

    Import the buffer and process modules manually. In your index.ios.js and index.android.js, add this to the first line:

    import process from 'process';
    import buffer from 'buffer';
    global.Buffer = buffer.Buffer
    

    try to stop the running React Native Packager, and run:

    rm -rf $TMPDIR/react-*
    

    and start it again

    You are good to go!

提交回复
热议问题