Expo and Rescript React Native build error using EAS

Hey all,

I integrated Rescript into my Expo project, and everything was going swimmingly until today when I used EAS to build. rescript-react-native was causing problems for me, and the answer wasn’t immediately obvious. The Xcode logs were huge, so it took a couple tries to figure out what exactly was going wrong. I’m putting the solution here for posterity. I’ll put an issue on the github repo too. Maybe they want to put something in the docs about this.

This is the error I was getting:

"Error loading assets JSON from Metro. Ensure you've followed all 
expo-updates installation steps correctly. 

Unable to resolve module rescript-react-native/src/apis/Style.bs.js from 
/Users/expo/workingdir/build/components/rescript /<mycomponent>.bs.js: 

rescript-react-native/src/apis/Style.bs.js could not be found within the project or in these directories:

The problem is that rescript-react-native ships uncompiled, and when you run eas build it doesn’t upload your node_modules directory, and instead installs them on the EAS server, which, frankly, makes sense. So, to make rescript-react-native work properly, you need to run rescript build after you’ve installed the node_modules.

After some googling, I found you can do that quite easily by adding this line to your package.json:

  // ...
  "scripts": {
    // ...
    "eas-build-post-install": "yarn rescript clean && yarn rescript build"
  // ...

I hope I save someone a headache by posting this here.

1 Like

I answered here Build issues using Expo EAS · Discussion #764 · rescript-react-native/rescript-react-native · GitHub

The problem is: the location (and content!) of the generated JS files depends on your ReScript (bsconfig.json) configuration, so we can’t really provide a solid way for this kind of problem.
I guess something in the doc could help! You can make a quick PR here if you want: https://github.com/rescript-react-native/rescript-react-native.github.io/edit/src/docs/install.md

1 Like

Yeah that all makes sense. I figured there was a sensible reason why the JS files weren’t generated. I’ll make a PR when I get a chance.