我正在尝试构建一个条形码扫描仪网络应用程序。我在网上找到了一些代码示例,但是当我运行yarn start-web
时出现以下错误:
编译失败。
./node_modules/expo/build/Notifications/Notifications.js尝试导入错误:"设备事件发射器"未从"反应本机"导出。
包.json
{
"name": "BarcodeExpo",
"version": "0.1.0",
"private": true,
"devDependencies": {
"jest-expo": "~27.0.0",
"react-native-scripts": "1.14.0",
"react-test-renderer": "16.3.1"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "jest",
"start-web": "react-scripts start",
"build-web": "react-scripts build"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"expo": "32.0.0",
"query-string": "^6.2.0",
"react": "16.7.0",
"react-art": "^16.7.0",
"react-dom": "^16.7.0",
"react-native": "0.57.8",
"react-native-web": "^0.9.13",
"react-router-dom": "^4.3.1",
"react-router-native": "^4.3.0",
"react-scripts": "^2.1.3"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
应用.js
'use strict';
import React, { Component } from 'react';
import { Text, View, StyleSheet, Alert } from 'react-native';
import { Constants, BarCodeScanner, Permissions } from 'expo';
export default class App extends Component {
state = {
hasCameraPermission: null
};
componentDidMount() {
this._requestCameraPermission();
}
_requestCameraPermission = async () => {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
this.setState({
hasCameraPermission: status === 'granted',
});
};
_handleBarCodeRead = data => {
Alert.alert(
'Scan successful!',
JSON.stringify(data)
);
};
render() {
return (
<View style={styles.container}>
{this.state.hasCameraPermission === null ?
<Text>Requesting for camera permission</Text> :
this.state.hasCameraPermission === false ?
<Text>Camera permission is not granted</Text> :
<BarCodeScanner
onBarCodeRead={this._handleBarCodeRead}
style={{ height: 200, width: 200 }}
/>
}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
}
});
这可能是世博会模块中的一个错误吗?
编辑
我创建了一个存储库 (https://github.com/albertski/barcode),它基本上具有默认的 Expo 项目,但一旦我import { Constants, BarCodeScanner, Permissions } from 'expo';
添加到我的 App.js 文件并运行yarn start-web
我就会收到错误。
我认为这里的问题是我正在尝试在网络应用程序上使用BarCodeScanner
,但这仅适用于IOS/Android。