React-Native无法parsing模块

我收到以下错误:

Dec 16 20:03:26 NathanHyland Bunny [21876]:无法parsing/Users/nhyland/Documents/react-native/Bunny/index.ios.js中的模块socket.io-client / socket.io:无效的目录/ Users /node_modules/socket.io-client/socket.io Dec 16 20:03:26 NathanHyland syslogd [21710]:ASL Sender Statistics

我的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); 

我试图直接链接到node_modules中的文件夹/文件,这是行不通的,我试过不同的方式导入,没有bueno。

通过npm install socket.io-client安装就好了,我可以在节点模块中看到它。

任何想法,为什么它不会让我import?

对于将来在这个问题上着陆的人,请在你的requirepath中包含“dist”文件夹,如下所示:

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

请参阅讨论此处的github问题。

 import io from 'socket.io-client'; 

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

package.json文件

 "dependencies": { "react": "16.0.0-alpha.12", "react-native": "0.47.1", "socket.io-client": "2.0.3" } 
 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';