我有一个react-native项目,在安装了带有依赖项(react-native-svg)的victory-native程序包后,我得到了以下错误:
[图像出现仿真器错误] [1]
我的 package.json 是:
{
"name": "ProjectName","version": "0.0.1","private": true,"scripts": {
"android": "react-native run-android","ios": "react-native run-ios","start": "react-native start","test": "jest","lint": "eslint ."
},"dependencies": {
"@react-native-community/masked-view": "^0.1.7","native-base": "^2.13.12","react": "16.9.0","react-native": "0.61.5","react-native-gesture-handler": "^1.6.0","react-native-safe-area-context": "^0.7.3","react-native-screens": "^2.0.0-alpha.34","react-native-svg": "^12.0.3","react-native-vector-icons": "^6.6.0","react-navigation": "^4.3.1","react-navigation-drawer": "^2.4.7","react-navigation-stack": "^2.3.1","realm": "^5.0.0","victory-native": "^34.1.0"
},"devDependencies": {
"@babel/core": "7.8.7","@babel/runtime": "7.8.7","@react-native-community/eslint-config": "0.0.5","babel-jest": "24.9.0","eslint": "6.8.0","jest": "24.9.0","metro-react-native-babel-preset": "0.56.4","react-test-renderer": "16.9.0"
},"jest": {
"preset": "react-native"
}
}
[1]: https://i.stack.imgur.com/cfsFZ.png
Here is my **HomeScreen.js** with a simplified code. The code is written mainly with the native-base components:
import React,{ Component } from 'react'
import { Container,Button,Text,Header,Icon,Left,Right,Body,View,Title,Drawer,List,ListItem } from 'native-base';
import { VictoryPie } from 'victory-native';
export default class HomeScreen extends Component {
constructor(props) {
super(props)
this.state = {};
this.getResponse = this.getResponse.bind(this);
}
async getResponse() {
await fetch('http://localhost:3000/')
.then((response) => response.json())
.then(responseJson => {
console.log("HERE IS THE RESPONSE ",responseJson)
})
}
render() {
const SampleData = [
{ element1: 1,value: 13000 },{ element2: 2,value: 16500 },{ element3: 3,value: 14250 },{ element4: 4,value: 19000 }
];
let pie = <VictoryPie
data={SampleData}
/>
let pageContent = <Container>
{pie}
</Container>
return (
<Container>
<Header>
<Left>
<Button transparent
onPress={() => this.drawer._root.open()}>
<Icon name='menu' />
</Button>
</Left>
<Body>
<Title>App Title</Title>
</Body>
<Right>
<View></View>
</Right>
</Header>
<Drawer
ref={(ref) => { this.drawer = ref }}
content={
<Container>
<List>
<ListItem><Text>Some</Text></ListItem>
<ListItem><Text>Some</Text></ListItem>
<ListItem><Text>Some</Text></ListItem>
<ListItem><Text>Some</Text></ListItem>
<ListItem><Text>Some</Text></ListItem>
</List>
</Container>
}
onClose={() => this.drawer._root.close()}
>
{pageContent}
</Drawer>
</Container>
);
}
};
我尝试过的事情:
-
重新启动缓存
- 删除node_modules文件夹
- 执行 npm-install
- 执行 npm start---reset-cache
-
清洁缓存
- 执行 npm缓存清理--force
- 执行 npm缓存清理--force
-
手动安装react-native-svg
- 我什至尝试使用旧版本的react-native-svg
- “ react-native-svg”:“ 11.0.1”
- 我在模拟器上删除了该应用,然后重新安装。
PS:
我没有在ios上测试,只有android。