React-Native Unable to resolve module

I get the following error:

Dec 16 20:03:26 NathanHyland Bunny [21876]: Failed to resolve socket.io-client / socket.io module from / Users / nhyland / Documents / react -native / Bunny / index.ios.js: Invalid directory / Users / node_modules / socket.io-client / socket.io Dec 16 20:03:26 NathanHyland syslogd [21710]: ASL Sender Statistics

My index.io.js:

var React = require('react-native');
var {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    TouchableHighlight
    } = React;

import './UserAgent';
window.navigator.userAgent = "react-native";
var _ = require('lodash');
var io = require('socket.io-client/socket.io');

class Bunny extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
            <View style={styles.container}>
                <Text style={styles.welcome}>
                    Welcome to React Native!
                </Text>
                <Text style={styles.instructions}>
                    To get started, edit index.ios.js
                </Text>
                <Text style={styles.instructions}>
                    Press Cmd+R to reload,{'\n'}
                    Cmd+D or shake for dev menu
                </Text>
                <TouchableHighlight onPress={() => {

      }}><Text>Test</Text></TouchableHighlight>
            </View>
        );
    }
}


var styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
    },
    welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
    },
    instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5,
    },
});

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

I tried to link directly to the folder / file in node_modules and this does not work, I tried different import methods without bueno.

It installs just fine through npm install socket.io-client, I see it in node -modules.

Any idea why this won't let me import?

+4
source share
3

, , "dist" :

var io = require('socket.io-client/dist/socket.io');

. github, .

+2
import io from 'socket.io-client';

===============

package.json file

"dependencies": {
    "react": "16.0.0-alpha.12",
    "react-native": "0.47.1",
    "socket.io-client": "2.0.3"
}
+1
var React = require('react-native');

var {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    TouchableHighlight
    } = React;

=============================================

import React, {Component} from 'react';

import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableHighlight
} from 'react-native';
-1
source

Source: https://habr.com/ru/post/1620467/


All Articles