【发布时间】:2019-10-11 10:21:03
【问题描述】:
我的 SVG 组件有问题。我认为我所做的一切都正确,但是在编译之后我不断收到这个错误:
Unable to resolve "./elements/Marker" from "node_modules\react-native-svg\src\ReactNativeSVG.ts"
Failed building JavaScript bundle.
有人可以检查我在下面提供的代码并告诉我出了什么问题吗?我目前正在开发最新的 Expo SDK 和 react-native-svg 包。哦,还有一件更重要的事情要说。我已经在 Expo-Snack 中对其进行了测试,并且成功了!
import React, { Component } from 'react';
import { View, StyleSheet, Dimensions } from 'react-native';
import Svg, { Defs, RadialGradient, Stop, G, Use, Path } from 'react-native-svg';
const { height, width } = Dimensions.get('window');
export default class SvgRadialBackground extends Component {
render() {
return (
<View
style={[
StyleSheet.absoluteFill,
{ alignItems: 'center', justifyContent: 'center' },
]}>
<Svg width={width} height={height}>
<Defs>
<RadialGradient
cx="50%"
cy="14%"
fx="50%"
fy="25%"
r="177%"
gradientTransform="matrix(0 .5 -1 0 .5 -0.146)"
id="prefix__b"
>
<Stop stopColor="#FFF" stopOpacity={0.5} offset="0%" />
<Stop stopColor="#003232" offset="100%" />
</RadialGradient>
<Path id="prefix__a" d="M0 0h375v667H0z" />
</Defs>
<G fill="none" fillRule="evenodd">
<Use fill="#244F77" xlinkHref="#prefix__a" />
<Use
fill="url(#prefix__b)"
style={{
mixBlendMode: 'soft-light',
}}
xlinkHref="#prefix__a"
/>
<Use stroke="#979797" xlinkHref="#prefix__a" />
</G>
</Svg>
</View>
);
}
}
【问题讨论】:
-
尝试删除
node_modules并再次运行npm i/yarn -
您好,感谢您的回复,但很遗憾没有成功。我必须深入挖掘:/
标签: android ios react-native react-native-svg