'EAS build fails : Unable to resolve module ./aws-exports
I am using expo 43 with Amplify when i run the app in mobile using
expo run:android
I can see my application running on mobile.
But when i try to create the build for same
eas build -p android
i am getting below error
Gradle build failed with unknown error. Please see logs for the "Run gradlew" phase
here the eas json
{
"cli": {
"version": ">= 0.46.0"
},
"build": {
"development": {
"distribution": "internal",
"android": {
"gradleCommand": ":app:assembleDebug"
},
"ios": {
"buildConfiguration": "Debug"
}
},
"preview": {
"distribution": "internal"
},
"production": {}
},
"submit": {
"production": {}
}
}
Here's the log for eas build
[stderr] 40 | import { enableScreens } from "react-native-screens";
Error: Unable to resolve module ./aws-exports from /root/workingdir/build/App.js:
None of these files exist:
* aws-exports(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
* aws-exports/index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
40 | import { enableScreens } from "react-native-screens";
41 | import Amplify from 'aws-amplify'
> 42 | import config from './aws-exports'
i have the aws-exports.js in root directory and it working for expo run:android
Solution 1:[1]
As mentioned by colinux EAS upload a copy of the repository on their servers and since aws-exports is a part of .gitignore, it was not uploaded at the server and hence we have the build error. Please read colinux's answer for more details on this.
The solution here is to add these 2 lines in your package JSON.
1. "aws-export": "echo 'Update Expo AWS_EXPORTS secret with value: \n\n' && cat aws-exports.js |base64"
2. "eas-build-pre-install": "echo $AWS_EXPORTS | base64 -di > ./aws-exports.js"
Note: There a small change here in step 2. instead of base64 -d, we have to use base64 -di.
This is because the older cli was not able to deocde newline and other chars. You can check more details here:
decode base64: invalid input
This part resolves the build issue i posted. I was getting few more build errors realted to app:mergeReleaseResources FAILED
This link should help you out in case of Duplicate resources error: Duplicate resources error
After resolving these errors you should get a successfule build from EAS.
And in case you want an .apk file instead of .aap. Please create a dev profile as mentioned below: Configuring a profile to build apks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ahmed Anwar |
