Sendbird SDK not working with React Native - node.js

I am following sendbird's tutorial on building a chat app with react-native, and i get the following error when I try to import sendbird sdk:
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
I deleted node_modules folder and run npm install again, cleaned npm cache and cleared watchman watches but couldn't fix it.
Any thoughts on this issue ?
update : adding code
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>
);
}
});

Try using an earlier version of SendBird's JS SDK. Based on my own testing this issue is introduced in SDK v. 2.4.19. My setup works with sendbird#2.4.18 and react-native#0.27.2.
The sudden appearance of this problem in a patch strongly suggests a bug in the SDK or the introduction of an undocumented API change (changelog), which is basically a bug as well.
To install a specific version of an npm package:
npm i --save PACKAGE_NAME#MAJOR.MINOR.PATCH, e.g.
npm i --save sendbird#2.4.18.
You can view all available versions of the sdk by running
npm info sendbird.

The official word I got from Sendbird when I reported the same issue. I haven't tried the newly released 3.0. So can't speak to that.
Harry Kim (SendBird) Jul 6, 01:51 PDT
Thank you for contacting SendBird support.
We recommend to use below packages to run SendBird properly.
"react-native": "0.20.0",
"react-native-button": "1.4.2",
"react-native-gifted-messenger": "0.0.18",
"react-native-gifted-spinner": "0.0.3",
"react-native-popup": "0.5.2",
"sendbird": "^2.4.20"
Regard, Harry

Related

Create React App and JEST property matchers

I've got this component that I've simplified for this example as part of a bigger create react app
import React from 'react';
function myVersion() {
return (
<p className={'ActivateSound--para'} data-testid={`version`}>
Version {process.env.REACT_APP_VERSION} has loaded, congrats!
</p>
);
}
export { myVersion };
and in the env I get the version from package.json
REACT_APP_VERSION=$npm_package_version
but in the test I've got
import React from 'react';
import { myVersion } from '../components/my-version';
import { render, screen, cleanup, fireEvent } from '#testing-library/react';
afterEach(cleanup);
describe('my version component', () => {
test('snapshot hasnt changed', () => {
expect(container.firstChild).toMatchSnapshot();
});
});
I am now looking at https://jestjs.io/docs/snapshot-testing#property-matchers. It seems I can exclude the version number somehow, I've tried a bunch of attempts but it's not ignoring the version number
expect(container.firstChild).toMatchSnapshot({
screen.getByTestId('version'): expect.any(String)
});

How to install a wsdl connection in react-native

I'm trying to establish aa wsdl connection. I get the following error. is there anyone who can help?
my connection code
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
var soap = require('soap');
var url = 'https://localhost:44379/service/ozelekranservice.svc?wsdl';
var args = {User : '15460036927', Password : '123'};
type Props = {};
export default class App extends Component<Props> {
render() {
soap.createClientAsync(url).then((client) => {
console.warn(client.Login(args));
return client.Login(args);
}).then((result) => {
console.warn(result);
});
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
</View>
);
}
}
error code
url:http://10.0.3.2:8081/index.delta?platform=andoid&dev=true&minify=false
body:{"orginModulePath":"
C:\users\...\node_modules\soap\lib\client.js","targetModuleName":"assert","message":"Unable to resolve module'assert'from
'C:\users\...\node_modules\soap\lib\client.js':Module 'assert' does not exist in the Haste module map\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n
Clear watchman watches:'watchman watch-del-all'.\n
Delete the 'node_modules' folder: 'rm -rf node_modules &&nom install'.\n
3.Reset Metro Bundler cache:'rm -rf/tmp/metro-bundler-chace-*' or 'npm start -- --reset-chace'.\n
Remove haste chace:'rm -rf /tmp/haste-mat-react-native-packager-*'.","errors":[{"description":"Unable to resolve module 'assert'from
'C:\users\...\node_modules\soap\lib\client.js': Module 'assert' does not exist in the Haste module map\n\nThis might be related to

How can I use node "fs" in electron within angular 5

I try to use Electron and Angular5 to write my first desktop App but unfortunately i am stuck in using the fs module. It seems that I have imported fs correctly (no errors within Visual Studio Code and code completion) but when i tried using "fs.readFile" the console prints out this error:
Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_2_fs__.readFile is not a function
This is the code of my service so far:
import { Injectable } from '#angular/core';
import { ElectronService } from 'ngx-electron';
import * as fs from 'fs';
import { OpenDialogOptions } from 'electron';
#Injectable()
export class FileService {
dialog = this._electronService.remote.dialog;
window = this._electronService.remote.getCurrentWindow();
constructor(private _electronService: ElectronService) { }
loadFileContent(): void{
this.dialog.showOpenDialog(this.window, {},(fileNames) => {
if(fileNames === undefined){
console.error("no files selected!");
return;
}
fs.readFile(fileNames[0], "utf-8", (err, data) => {
if(err){
console.error("Cannot read file ",err);
return;
}
console.log("The content of the file is : ");
console.log(data);
});
});
}
}
Do I miss something here? Seems that fs is not loaded or something? Thanks for your help everyone!
You can also use remote.require to load native node modules from ngx-electron.
fs;
constructor(private _electronService: ElectronService) {
this.fs = this._electronService.remote.require('fs');
}
I found the answer with the help of the comments from kimy82!
First i needed to get the Angular5 webpack.config.js by simply using:
ng eject
After that i opened up the webpack.config.js and added the following:
"target": "node-webkit"
Simply "node" did not work out for me and since electron uses a Chromium this should be ok.
Thanks everyone!
Your browser cannot access the file system on the server. fs should not be loaded in the browser

How should I mock out react-native-extended-stylesheet in Mockery.js?

I have started using ava.js in my react native project. I have an AVA setup file that looks like this (from the Ignite starter project):
import mockery from 'mockery';
import m from 'module';
// inject __DEV__ as it is not available when running through the tests
global.__DEV__ = true;
// We enable mockery and leave it on.
mockery.enable();
// Silence the warnings when *real* modules load... this is a change from
// the norm. We want to opt-in instead of opt-out because not everything
// will be mocked.
mockery.warnOnUnregistered(false);
// Mock any libs that get called in here
// I'm looking at you react-native-router-flux, reactotron etc!
mockery.registerMock('reactotron-react-native', {});
mockery.registerMock('react-native-fetch-blob', {});
mockery.registerMock('reactotron-redux', {});
mockery.registerMock('reactotron-apisauce', {});
mockery.registerMock('react-native-animatable', { View: 'Animatable.View' });
mockery.registerMock('react-native-vector-icons/Ionicons', {});
mockery.registerMock('react-native-vector-icons/FontAwesome', {});
mockery.registerMock('react-native-config', {
CLIENT_API_USERNAME_DEV: 'username',
CLIENT_API_PASSWORD_DEV: 'password'});
mockery.registerMock('react-native-device-info', {});
mockery.registerMock('react-native-uuid-generator', {});
mockery.registerMock('react-native-cached-image', {});
mockery.registerMock('react-native-extended-stylesheet', {
EStyleSheet: {
create: {}
}
});
// mock i18n as it uses react native stufff
mockery.registerMock('react-native-i18n', {
t: key => key,
});
// Mock all images for React Native
const originalLoader = m._load;
m._load = (request, parent, isMain) => {
if (request.match(/.jpeg|.jpg|.png|.gif$/)) {
return { uri: request };
}
return originalLoader(request, parent, isMain);
};
I have created a test on a simple component I am using. However, in our app, we started using react-native-extended-stylesheet. This means we need to mock that module to get our tests to run and it is exactly this that I am having trouble with.
I have a test that looks something like this:
import { test } from 'ava';
import React from 'react';
import TheComponent from '../../App/Components/TheComponent';
import { render } from 'enzyme';
const wrapper = render(<TheComponent/>);
test('component exists', (t) => {
t.is(wrapper.length, 1);
});
TheComponent imports the following style code:
// #flow
import { Platform } from 'react-native';
import EStyleSheet from 'react-native-extended-stylesheet';
import { ApplicationStyles, Metrics, Colors, Fonts } from '../../Themes/';
const height = Math.floor((Metrics.screenWidth / 2) * Metrics.defaultImageRatio);
const width = Metrics.screenWidth / 2;
export default EStyleSheet.create({
...ApplicationStyles.screen,
item: {
width,
height,
justifyContent: 'center',
alignItems: 'center',
margin: 0,
backgroundColor: 'transparent',
}, // more styles here...
});
I have seen a few examples of using mockery's registerMock but to be honest I'm not sure I grok them all. It seems to me that I should be using something like what I used above:
mockery.registerMock('react-native-extended-stylesheet', {
EStyleSheet: {
create: {}
}
});
But running that gives me the following error:
_reactNativeExtendedStylesheet2.default.create(_extends({},
^
TypeError: _reactNativeExtendedStylesheet2.default.create is not a function
So what is the correct syntax in registerMock to get this to run? (I welcome other answers too if they address the underlying issue - how can I get on and test my component?)

How to load google maps javascript api in Aurelia javascript application?

I found npm module google-maps-api and installed it (npm install google-maps-api) but I can't figure out how to import it with systemjs/jspm (jspm cannot find this module). Here's the configuration from my config.js:
"paths": {
"*": "app/dist/*.js",
"github:*": "app/jspm_packages/github/*.js",
"npm:*": "app/jspm_packages/npm/*.js" }
So, when I try do something like this:
import {mapsapi} from 'google-maps-api';
I get the following error in browser console:
GET https://localhost:44308/app/dist/google-maps-api.js 404 (Not Found)
Looking at the filesystem I see that npm installed the module under app/node_modules/google-maps-api so how do I reference it in the import clause from Aurelia module?
I found a solution and answering my own question here:
I finally figured how to install it with jspm, so you just need to give a hint to jspm to install it from npm like so:
jspm install npm:google-maps-api
After jspm completes installation, import (no {} syntax) works fine:
import mapsapi from 'google-maps-api';
then I inject it in constructor and instantiate geocoder api:
#inject(mapsapi('InsertYourGMAPIKeyHere'))
export class MyClass {
constructor(mapsapi) {
let that = this;
let maps = mapsapi.then( function(maps) {
that.maps = maps;
that.geocoder = new google.maps.Geocoder();
});
...
}
In order to create map on a div I use EventAggregator to subscribe for router:navigation:complete event and use setTimeout to schedule map creation:
this.eventAggregator.subscribe('router:navigation:complete', function (e) {
if (e.instruction.fragment === "/yourRouteHere") {
setTimeout(function() {
that.map = new google.maps.Map(document.getElementById('map-div'),
{
center: new google.maps.LatLng(38.8977, -77.0366),
zoom: 15
});
}, 200);
}
});
Here's a complete view-model example that uses attached() to link to your view.
import {inject} from 'aurelia-framework';
import mapsapi from 'google-maps-api';
#inject(mapsapi('your map key here'))
export class MapClass {
constructor(mapsAPI) {
this.mapLoadingPromise = mapsAPI.then(maps => {
this.maps = maps;
});
}
attached() {
this.mapLoadingPromise.then(() => {
var startCoords = {
lat: 0,
long: 0
};
new this.maps.Map(document.getElementById('map-div'), {
center: new this.maps.LatLng(startCoords.lat, startCoords.long),
zoom: 15
});
});
}
}
For everyone using Typescript and getting "Cannot find module 'google-maps-api'" error,
you need to add typings to the solution. Something like this works
declare module 'google-maps-api' {
function mapsapi(apikey: string, libraries?, onComplete?);
namespace mapsapi {
}
export = mapsapi;
}
and then import it like this
import * as mapsapi from 'google-maps-api';

Resources