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:
node_modules"
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.