Unable to Publish - Require fails on TTF [Solved]

#1

I have a create-react-native-app project, which works fine in development mode now, and which I was once able to publish using exp publish.

Now, when I run exp publish I get errors from the RN packager that it is unable to resolve a font. The font loads fine in development mode. I’m using code copied from an example that looks like:

    async componentWillMount() {
       await Font.loadAsync({
           'Roboto_medium': require('./fonts/Roboto_medium.ttf'),
       });

The error message:

Unable to resolve module `./fonts/Roboto_medium.ttf` from `/home/jeremy/repos/project/project/dist/App.js`: Directory /home/jeremy/repos/project/project/dist/fonts/Roboto_medium.ttf doesn't exist

Notice it complains “Directory …/Roboto_medium.tff” doesn’t exist. Its like I’m using a version of require that doesn’t understand that a ttf is a file which could be loaded. And indeed, if I change the name of the to “Roboto_medium.js” and require that one, this error goes away. But of course this cannot work and later in the packer I get:

SyntaxError /home/jeremy/repos/project/project/dist/fonts/Roboto_medium.js: Unexpected character '' (1:0)

If delete my font loader code entirely I still cannot publish, now I die in vector-icons with the same error from @expo/vector-icons:

[exp] Unable to resolve module `./fonts/Entypo.ttf` from `/home/jeremy/repos/project/project/node_modules/expo/node_modules/@expo/vector-icons/Entypo.js`: Directory /home/jeremy/repos/project/project/node_modules/expo/node_modules/@expo/vector-icons/fonts/Entypo.ttf doesn't exist

So another observation - no idea if it is related - is that when I run exp publish I get a warning: "Warning: Not using the Expo fork of react-native. See https://docs.getexponent.com/.". I believe this is expected when using create-react-native-app but nonetheless I changed the version of react-native I am using to use the fork and I STILL get this message.

This is from my yarn.lock

"react-native@https://github.com/expo/react-native/archive/sdk-15.0.0.tar.gz":
  version "0.42.0"
  resolved "https://github.com/expo/react-native/archive/sdk-15.0.0.tar.gz#4a808c2a5bf29e9658e819bab9053701b2984e06"
  dependencies:

Still I see these bold falsehoods from exp publish :

[exp] Making sure project is set up correctly...
-[exp] Warning: Not using the Expo fork of react-native. See https://docs.getexponent.com/.
[exp] Your project looks good!
[exp] Unable to find an existing exp instance for this directory, starting a new one...
...
#2

I found the answer looking at the files generated by an Expo IDE created project; I ended up just making an exp.json modeled after that but the only important part is “ttf” in the packagerOpts.assetExts.

  "packagerOpts": {
    "assetExts": ["ttf", "mp4"]
  },
1 Like