-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
undefined is not a constructor #4
Comments
Hello @obeleh, When is this error happening (build, test, start)? Can you share your |
I only have an App.js (mostly generated)
It happens onLoad |
The problem was being caused by a bad export in the library Could you please update to |
The problem is solved. But further along I get the following message. Probably a similar issue?
|
Unfortunately, I couldn't simulate it 😞. I ran the following code on a fresh project and everything worked just fine. Steps: $ react-native init rnUsbSerial
$ yarn add react-native-usbserial
$ react-native link react-native-usbserial
$ react-native start
$ react-native run-android
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import { UsbSerial } from 'react-native-usbserial'
const usbs = new UsbSerial();
export default class rnUsbSerial extends Component {
constructor(props) {
super(props);
async function getDeviceAsync() {
try {
const deviceList = await usbs.getDeviceListAsync();
const firstDevice = deviceList[0];
console.log(deviceList);
console.log(firstDevice);
if (firstDevice) {
const usbSerialDevice = await usbs.openDeviceAsync(firstDevice);
console.log(usbSerialDevice);
}
} catch (err) {
console.warn(err);
}
}
getDeviceAsync();
}
render() {
console.log(usbs);
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.android.js
</Text>
<Text style={styles.instructions}>
Double tap R on your keyboard to reload,{'\n'}
Shake or press menu button for dev menu
</Text>
</View>
);
}
}
const 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('rnUsbSerial', () => rnUsbSerial); Can you try to recreate your project under the conditions mentioned above? |
Wow that is totally different from what I did. Anyway I also ran into this: #3 And now I get:
PyCharm nor https://babeljs.io are giving parse errors. |
Hmmm, this error is quite generic 🤔. It's most likely to be a Pycharm error transpiling the javascript code. In order to run the snippet I've posted before I've used the following dependencies:
{
"name": "rnUsbSerial",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start",
"android": "react-native run-android",
"test": "jest"
},
"dependencies": {
"react": "16.0.0-alpha.12",
"react-native": "0.47.1",
},
"devDependencies": {
"babel-jest": "20.0.3",
"babel-preset-react-native": "^2.1.0",
"jest": "20.0.4",
"react-test-renderer": "16.0.0-alpha.12"
},
"jest": {
"preset": "react-native"
}
} Could you check if you're able to run and build it manually using these deps? |
I must be doing something wrong, can you point me in the right direction?
The text was updated successfully, but these errors were encountered: