Unable to loads fonts after upgrading SDK from 33 to 34. Fails with:
console.error: "fontFamily “monserrat-bold” is not a system font and has not been loaded through Font.loadAsync.
Here’s the loading stuff from App.js …Font Icons are not loaded either.
async function loadResourcesAsync() {
await Promise.all([
Asset.loadAsync([
require('./assets/images/splash.png'),
require('./assets/images/icon.png'),
require('./assets/images/icon-adaptive.png'),
require('./assets/images/vegan.png'),
require('./assets/images/vegetarian.png'),
require('./assets/images/cauldron.png'),
require('./assets/images/tabacos.png'),
require('./assets/images/qr-400.png'),
require('./assets/images/loading.gif')
]),
Font.loadAsync({
...Ionicons.font,
...MaterialCommunityIcons.font,
...Foundation.font,
'montserrat-regular': require('./assets/fonts/Montserrat-Regular.ttf'),
'montserrat-bold': require('./assets/fonts/Montserrat-Bold.ttf'),
}),
]);
}
wodin
August 8, 2019, 5:21pm
2
I think this was an issue (also affecting vector icons) that has since been fixed. See the following:
Hey everyone! This was a github issue , but it looks like updating to expo@34.0.3 and expo-font@6.0.1 fixes it
and
opened 04:40PM - 30 Jul 19 UTC
closed 10:21PM - 30 Jul 19 UTC
bug
## 🐛 Bug Report
### Environment
```
Expo CLI 3.0.6 environment info:
… System:
OS: macOS 10.14.5
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.6.0 - /usr/local/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.10.2 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
IDEs:
Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
npmPackages:
expo: ^34.0.1 => 34.0.2
react: 16.8.3 => 16.8.3
react-native: https://github.com/expo/react-native/archive/sdk-34.0.0.tar.gz => 0.59.8
react-navigation: ^3.11.1 => 3.11.1
npmGlobalPackages:
expo-cli: 3.0.6
```
Target: iOS
### Steps to Reproduce
<!--
How would you describe your issue to someone who doesn’t know you or your project?
Try to write a sequence of steps that anybody can repeat to see the issue.
Be specific! If the bug cannot be reproduced, your issue may be closed.
-->
### Expected Behavior
Icons to appear as expected
![IMG_4744](https://user-images.githubusercontent.com/6615285/62148108-0bef9f00-b2c7-11e9-83a9-92bffb61a58c.jpg)
### Actual Behavior
Icons show up as `?` in the Testflight app but looks OK in the Expo iOS client app on the iPhone.
Does not occur in Testflight app using SDK 33 before updating to SDK 34.
![IMG_4745](https://user-images.githubusercontent.com/6615285/62148106-0bef9f00-b2c7-11e9-8b2a-0d454a973b2c.jpg)
### Reproducible Demo
Upgrade from Expo following the instructions at https://blog.expo.io/expo-sdk-34-is-now-available-4f7825239319#59ef
The icons are obtained from `'@expo/vector-icons'` package. An example of using this will be
<FontAwesome name="angle-right" size={24} />
3 Likes
Thanks for chiming in here, @wodin !
1 Like
@wodin …does not work here …but did a couple of things and now it works.
I think the issue was having “react-native-elements” installed wich required “react-native-vector-icons”.
Wasn’t an issue before SDK 34. Seemed to have solved it …not sure I am actually using “react-native-elements” though, but I have a reference somewhere.
did you change your babel config? you need to use babel-preset-expo
1 Like
@notbrent are you saying my JavaScript is old-school? kidding
no I do not have that one …but it works now …I’m up and running again!
Just posted a couple of minutes before your post …thanks for replying!
Think I needed “react-native-vector-icons” to please “react-native-elements” somehow. Might be a smaller mess I need to clean up. Don’t think I use or should use “react-native-elements”.
Ok …I removed “react-native-vector-icons” and “react-native-elements” …and I’m back to the same.
My babel-preset-expo looks like this. Didn’t change it.
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
can you try to reproduce this on a new project and share that?
1 Like
Ok …I made an empty TabBar project.
Added fonts. The ‘space-mono’ font did not get loaded with a a loader like this:
async function loadResourcesAsync() {
await Promise.all([
Asset.loadAsync([
require('./assets/images/robot-dev.png'),
require('./assets/images/robot-prod.png'),
]),
Font.loadAsync({
...Ionicons.font,
...MaterialCommunityIcons.font,
...MaterialIcons.font,
...Foundation.font,
...FontAwesome.font,
'montserrat-regular': require('./assets/fonts/Montserrat-Regular.ttf'),
'montserrat-bold': require('./assets/fonts/Montserrat-Bold.ttf'),
'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf'),
}),
]);
}
If I remove these lines it works:
...MaterialCommunityIcons.font,
...MaterialIcons.font,
...Foundation.font,
...FontAwesome.font,
Does that make sense? I tried removing them individually, but no luck.
And not preloading them from my main project makes it load without errors …but …that is not entirely correct, right?
can you share the full new project that you reproduced this in? just on github would be good
1 Like
Is this good enought @notbrent ?
the problem is that you aren’t importing any of the fonts except for Ionicons
you can see that before the error in logs:
Can't find variable: MaterialCommunityIcons
* App.js:39:28 in loadResourcesAsync$
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:271:30 in invoke
if you change the import it works fine
import {
Ionicons,
MaterialCommunityIcons,
MaterialIcons,
Foundation,
FontAwesome,
} from '@expo/vector-icons';
1 Like
They need to be imported because they are referenced as variables …makes a lot of sense now …thanks a lot !!!
I’m amazed it worked before though …
i don’t think it did work in the way you expected before
@notbrent is it worth notising that it did not give errors on the items that was not imported, but rather on the last item in the array. So basicly it returns an error for an item that works and that made it really difficult finding the error because it was pointing at the wrong spot.
Thanks for helping me out!
Best …,
Andy
system
Closed
August 25, 2019, 1:43am
18
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.