在将Expo SDK版本升级到33之后,我得到了这个错误:
ENOENT: no such file or directory, scandir '.\node_modules\native-base\Fonts'
Failed building JavaScript bundle.发布于 2019-07-30 14:57:09
更新世博会可能导致与更新的@expo/vector-icons发生冲突。如果native-base模块被删除且未重新安装或问题未解决,
rm -rf node_modules && yarn install && expo start发布于 2019-08-02 02:17:02
Expo以一种新的方式加载字体:
https://docs.expo.io/versions/latest/sdk/font/
下面的示例基于原生数据库和expo文档中的示例。
https://github.com/GeekyAnts/NativeBase
您可能需要先运行以下命令:
expo install expo-font然后,在你的代码中:
import * as Font from 'expo-font'和
export default class App extends React.Component {
async componentDidMount() {
await Font.loadAsync({
'open-sans-bold': require('./assets/fonts/OpenSans-Bold.ttf'),
});
this.setState({ isReady: true });
}
// ...
}使用native-base/Fonts/Roboto.ttf的导入路径对我不起作用,但使用如下所示的相对路径有效:
await Font.loadAsync({
Roboto: require('../node_modules/native-base/Fonts/Roboto.ttf'),
Roboto_medium: require('../node_modules/native-base/Fonts/Roboto_medium.ttf')
});下面是一个稍微完整一点的示例:
export default class extends React.Component {
state = {
isReady: false,
};
async componentDidMount() {
await Font.loadAsync({
Roboto: require('../node_modules/native-base/Fonts/Roboto.ttf'),
Roboto_medium: require('../node_modules/native-base/Fonts/Roboto_medium.ttf')
});
this.setState({ isReady: true });
}
render() {
if (!this.state.isReady) {
return ( <AppLoading />);
}
return <Navigator />;
}
}https://stackoverflow.com/questions/57265472
复制相似问题