我正在关注使用react-native构建聊天应用程序的sendbird教程,当我尝试导入sendbird sdk时出现以下错误: Unable to resolve module http from .../SendbirdSample/node_modules/sendbird/SendBird.min.js: Unable to find th
Unable to resolve module http from .../SendbirdSample/node_modules/sendbird/SendBird.min.js: Unable to find this module in its module map or any of the node_modules/http and its parent directories
我删除了node_modules文件夹并再次运行npm install,清理了npm cache并清除了watchman watch但无法修复它.
有关这个问题的任何想法?
更新:添加代码
main.js
import React from 'react'; import { StyleSheet, Navigator } from 'react-native'; var Login = require('./components/login'); var Channels = require('./components/channels'); var ROUTES = { login: Login, channels: Channels }; module.exports = React.createClass({ renderScene: function(route, navigator) { var Component = ROUTES[route.name]; return <Component route={route} navigator={navigator} />; }, render: function() { return ( <Navigator style = { styles.container } initialRoute={ {name:'login'} } renderScene={this.renderScene } configureScene={ () => { return Navigator.SceneConfigs.FloatFromRight; } } /> ); }});
login.js
import React from 'react'; import { StyleSheet, Navigator } from 'react-native'; var Login = require('./components/login'); var Channels = require('./components/channels'); var ROUTES = { login: Login, channels: Channels }; module.exports = React.createClass({ renderScene: function(route, navigator) { var Component = ROUTES[route.name]; return <Component route={route} navigator={navigator} />; }, render: function() { return ( <Navigator style = { styles.container } initialRoute={ {name:'login'} } renderScene={this.renderScene } configureScene={ () => { return Navigator.SceneConfigs.FloatFromRight; } } /> ); } });
channels.js
import React from 'react'; import { View, Text, StyleSheet } from 'react-native'; var sendbird = require('sendbird'); module.exports = React.createClass({ render: function() { return ( <View style={styles.container}> <Text style={{color: '#fff'}}>Channels</Text> </View> ); } });尝试使用早期版本的SendBird JS SDK.根据我自己的测试,SDK v.2.4.19中引入了此问题.我的设置适用于sendbird@2.4.18和react-native@0.27.2.
在补丁中突然出现此问题强烈暗示SDK中的错误或引入未记录的API更改(changelog),这基本上也是一个错误.
要安装特定版本的npm包:
npm i –save PACKAGE_NAME@MAJOR.MINOR.PATCH,例如
npm i –save sendbird@2.4.18.
您可以通过运行查看sdk的所有可用版本
npm info sendbird.