[Ethereum] Cannot import Ethereum web3.js in React Native application

importweb3js

I'm trying to import the Ethereum web3.js library into a React Native project.

I've followed the React Linking Libraries instructions, installing the web3.js package and linking it with the commands:

$ npm install web3 --save
$ react-native link

My index.ios.js file looks as follows:

import { default as Web3 } from 'web3';

import React, { Component } from 'react';
import { AppRegistry, Text } from 'react-native';

class ReactProject extends Component {
  render() {
    return (
      <Text>Hello world!</Text>
    );
  }
}

AppRegistry.registerComponent('ReactProject', () => ReactProject);

The error message I receive in the simulator when I run the app {"type":"InternalError","message":"react-packager has encountered an internal error, please check your terminal error output for more details"} is not very helpful as the terminal shows only the same message.

How do I go about importing this library, into other projects such as React-Native?

Best Answer

Fixed: https://github.com/ethereum/web3.js/issues/576

Edit The Following File

/node_modules/bignumber.js/bignumber.js

edit as follows:

-if ( !crypto ) try { crypto = require('crypto'); } catch (e) {}
+if ( !crypto ) try { crypto = require('crypto-js'); } catch (e) {} 

Web3 Version: 0.18.2

Import in respective file

var Web3 = require('web3'); or import { default as Web3 } from 'web3';
Related Topic