EAS build fails with simple boilerplate AWS Amplify

Following the AWS Amplify documentation for Expo with the steps below, building with EAS build fails with

[RUN_FASTLANE] › Executing baseline » Bundle React Native code and images
[RUN_FASTLANE]     the transform cache was reset.
[RUN_FASTLANE] › Generating debug baseline » baseline.app.dSYM
[RUN_FASTLANE] ▸ ** ARCHIVE FAILED **
[RUN_FASTLANE] ▸ The following build commands failed:
[RUN_FASTLANE] ▸ 	PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/Rax/Library/Developer/Xcode/DerivedData/baseline-hhrsifdg
[RUN_FASTLANE] ▸ (1 failure)
[RUN_FASTLANE] ** ARCHIVE FAILED **
[RUN_FASTLANE] 
[RUN_FASTLANE] 
[RUN_FASTLANE] The following build commands failed:
[RUN_FASTLANE] 	PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/Rax/Library/Developer/Xcode/DerivedData/baseline-xxxxxxx
[RUN_FASTLANE] (1 failure)
[RUN_FASTLANE] Exit status: 65
[RUN_FASTLANE] 
[RUN_FASTLANE] +-------------+-------------------------+
[RUN_FASTLANE] |           Build environment           |
[RUN_FASTLANE] +-------------+-------------------------+
[RUN_FASTLANE] | xcode_path  | /Applications/Xcode.app |
[RUN_FASTLANE] | gym_version | 2.205.2                 |
[RUN_FASTLANE] | sdk         | iPhoneOS15.2.sdk        |
[RUN_FASTLANE] +-------------+-------------------------+
[RUN_FASTLANE] Looks like fastlane ran into a build/archive error with your project
[RUN_FASTLANE] It's hard to tell what's causing the error, so we wrote some guides on how
[RUN_FASTLANE] to troubleshoot build and signing issues: https://docs.fastlane.tools/codesigning/getting-started/
[RUN_FASTLANE] Before submitting an issue on GitHub, please follow the guide above and make
[RUN_FASTLANE] sure your project is set up correctly.
[RUN_FASTLANE] fastlane uses `xcodebuild` commands to generate your binary, you can see the
[RUN_FASTLANE] the full commands printed out in yellow in the above log.
[RUN_FASTLANE] Make sure to inspect the output above, as usually you'll find more error information there
[RUN_FASTLANE] 
[RUN_FASTLANE] [!] Error building the application - see the log above
[RUN_FASTLANE] Error: Fastlane build failed with unknown error. Please refer to the "Run fastlane" and "Xcode Logs" phases.
Fastlane errors in most cases are not printed at the end of the output, so you may not find any useful information in the last lines of output when lo
[CLEAN_UP_CREDENTIALS] Destroying keychain - XXXXXXXXXX.keychain
[CLEAN_UP_CREDENTIALS] Removing provisioning profile

Build failed
Fastlane build failed with unknown error. Please refer to the "Run fastlane" and "Xcode Logs" phases.
Fastlane errors in most cases are not printed at the end of the output, so you may not find any useful information in the last lines of output when lo
    Error: npx exited with non-zero code: 1

The failure varies from build to build but always involves two [RUN_FASTLANE] ** ARCHIVE FAILED ** failures just before exiting.

What am I doing wrong?


Steps followed:

  1. Create a new project with expo init closing TypeScript with basic navigation.
  2. Install AWS Amplify dependencies with
    expo install aws-amplify aws-amplify-react-native @react-native-community/netinfo  @react-native-async-storage/async-storage @react-native-picker/picker
    
  3. Pull my AWS Amplify project with amplify pull making the following selections:
    ? Select the authentication method you want to use: AWS profile
    ? Please choose the profile you want to use amplify-cli
    ? Which app are you working on? XXXXXXXX
    Backend environment 'dev' found. Initializing...
    ? Choose your default editor: IntelliJ IDEA
    ? Choose the type of app that you're building javascript
    Please tell us about your project
    ? What javascript framework are you using react-native
    ? Source Directory Path:  /
    ? Distribution Directory Path: /
    ? Build Command: eas build --profile development --platform ios --local
    ? Start Command: expo start --dev-client
    
  4. Add specified AWS Amplify boilerplate to App.tsx:
    import { Amplify } from 'aws-amplify'
    import awsconfig from 'aws-exports'
    
    Amplify.configure(awsconfig)
    
  5. Build with
    eas build --profile development --platform ios --local
    

{
  "name": "amptest",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject",
    "test": "jest --watchAll"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/vector-icons": "^13.0.0",
    "@react-native-async-storage/async-storage": "^1.17.4",
    "@react-native-community/netinfo": "8.2.0",
    "@react-native-picker/picker": "2.4.0",
    "@react-navigation/bottom-tabs": "^6.0.5",
    "@react-navigation/native": "^6.0.2",
    "@react-navigation/native-stack": "^6.1.0",
    "aws-amplify": "^4.3.22",
    "aws-amplify-react-native": "^6.0.4",
    "expo": "~45.0.0",
    "expo-asset": "~8.5.0",
    "expo-constants": "~13.1.1",
    "expo-dev-client": "~0.9.5",
    "expo-font": "~10.1.0",
    "expo-linking": "~3.1.0",
    "expo-splash-screen": "~0.15.1",
    "expo-status-bar": "~1.3.0",
    "expo-system-ui": "~1.2.0",
    "expo-web-browser": "~10.2.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-native": "0.68.2",
    "react-native-safe-area-context": "4.2.4",
    "react-native-screens": "~3.11.1",
    "react-native-web": "0.17.7"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@types/react": "~17.0.21",
    "@types/react-native": "~0.66.13",
    "jest": "^26.6.3",
    "jest-expo": "~45.0.0",
    "react-test-renderer": "17.0.2",
    "typescript": "~4.3.5"
  },
  "private": true
}

you should look at your full xcode build logs, you will see more information about what the error is. the specific error you are seeing occurs when your js bundle fails.

click download here

open it in vscode or the editor of your choice, find the error message (I searched for “PhaseScriptExecution Bundle” to jump there) and then scroll until you see the error.

it looks like your aws-exports.js file is not included in your project. if you are not adding this to git then you will need to somehow make it available on the build worker (you can think of eas build as like other CI services - if they were to clone your project from github and your aws-exports.js wasn’t in git, your build would fail). more info on how eas build uploads your project: fyi/eas-build-archive.md at main · expo/fyi · GitHub

in the future you can refer to this page for more information on how to debug build errors on eas build: Troubleshooting build errors and crashes - Expo Documentation

1 Like

@notbrent Wow! I wish we’d met earlier! That would have saved me a day and a half.

But here’s the problem: AWS Amplify adds aws-exports.js to .gitignore in a section bounded by #amplify-do-not-edit-begin/end. This makes some sense since the file contains API keys. But reasonable or not, it creates a problem. Out of the box, AWS Amplify can’t work with eas build. Manually disabling that ignore fixes the problem, of course; but that’s clearly not a long term solution, especially since Amplify may update that section in the .gitignore (and put it in an unknown position in that file).

this is in fact a pretty standard thing for CI services! for example, if you were to run your build on GitHub Actions you would also need to figure out how you want to get your aws-exports.js to your project if you don’t commit it to git.

in the doc I linked to there is more information about how to do this: fyi/eas-build-archive.md at main · expo/fyi · GitHub

basically:

  1. convert your aws-exports.js into a base64 encoded string
  2. add that to your project secrets
  3. add an “eas-build-pre-install” script to take that secret from an env var and write it to aws-exports.js - for example: echo "$AWS_EXPORTS" | base64 -d > aws-exports.js (assuming aws-exports.js is in the root of your project directory and your secret is named AWS_EXPORTS)

a somewhat easier alternative:

the doc also explains that you can create a .easignore file. this is an alternative to .gitignore that we only use for uploading to EAS Build. so, you can copy your .gitignore to a new file called .easignore and then remove aws-exports.js from it. now eas-cli will use .easignore rather than .gitignore to determine which files to include when uploading to EAS Build

1 Like

@notbrent Will do! But doesn’t the presence of .easignore mean that all .gitignores are ignored? I’d have to make sure everything was in .easignore?

BTW, where do I find those logs after a --local build?

off of the top of my head i’m not sure, take a look at these env vars as they may be helpful Running builds on your own infrastructure - Expo Documentation

i’m not sure i understand the gitignore question. if you put .easignore in the root of your project, that will be used rather than .gitignore inside of your project (at the root and nested).

I’m not sure if this is relevant to your question, but EAS does not ignore stuff in $XDG_CONFIG_HOME/git/ignore or $GIT_DIR/info/exclude.

There’s a feature request to improve that here.

I mean that if I have an .easignore I’ll need to update it every time any .gitignore anywhere in my project (some of which I may have been put there by tools, in my case) changes, right? That seems harder to maintain than just putting !aws-exports.js in the root .gitignore.

Yes, you’re right.

To avoid that, do it with EAS Secrets instead. i.e. as Brent said, store the contents of the file in a secret and then write the file using the eas-build-pre-install hook.

I faced similar kind of issue last time, I am still searching for some proper solution Same issue still no fix to this.

Could you elaborate on why the two solutions above don’t work for you?

I’m having the same problem but for me it seems it’s not related to aws-exports because it’s not even mentioned on my build log.

I wasn’t understanding why my build failed so I created another project only to see what libraries were causing problems and I discovered it’s the AWS Amplify dependencies.

This is what I’m getting. If I’m reading correctly the problem is “main.jsbundle does not exist”. I found that most people solve this with XCode, but I’m using expo so I can’t follow their steps.
Hopefully somebody can see what I’m doing wrong.

Thanks

Compiling faceCompareFinal » AppDelegate.mm
› Linking faceCompareFinal » faceCompareFinal
:warning: ld: duplicate method ‘+moduleName’ in
┌─[category]: ExpoBridgeModule-44dcc1d614b6278ae7a3d38b9d3e0eac.o ExpoModulesCore/libExpoModulesCore.a
└─[class]: ExpoBridgeModule-d488f5e84c1630877ee62a284bb2f96c.o ExpoModulesCore/libExpoModulesCore.a
› Generating debug faceCompareFinal » faceCompareFinal.app.dSYM
› Executing faceCompareFinal » Bundle React Native code and images
the transform cache was reset.

:x: error: File /Users/expo/Library/Developer/Xcode/DerivedData/faceCompareFinal-bqvqbicvmlfmpncjojyaopvajvmh/Build/Intermediates.noindex/ArchiveIntermediates/faceCompareFinal/BuildProductsPath/Release-iphoneos/faceCompareFinal.app/main.jsbundle does not exist. This must be a bug with React Native, please report it here: Issues · facebook/react-native · GitHub

Run script build phase '[CP-User] Generate app.config for prebuilt Constants.manifest' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'EXConstants' from project 'Pods')

▸ ** ARCHIVE FAILED **
▸ The following build commands failed:
▸ PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/expo/Library/Developer/Xcode/DerivedData/faceCompareFinal-bqvqbicvmlfmpncjojyaopvajvmh/Build/Intermediates.noindex/ArchiveIntermediates/faceCompareFinal/IntermediateBuildFilesPath/faceCompareFinal.build/Release-iphoneos/faceCompareFinal.build/Script-00DD1BFF1BD5951E006B06BC.sh (in target ‘faceCompareFinal’ from project ‘faceCompareFinal’)
▸ (1 failure)
** ARCHIVE FAILED **

Hi @mrpiet

It looks like you have two different versions of expo-modules-core installed.

Please run npx expo-doctor

This is actually just a symptom of the real problem.

Thanks for your help.

Everything seems to be ok according to expo-doctor.

Strange. Please post the dependencies and devDependencies sections from package.json

Here they are:

{
  
  "dependencies": {
    "@react-native-async-storage/async-storage": "1.17.11",
    "@react-native-community/netinfo": "9.3.7",
    "amazon-cognito-identity-js": "^6.3.1",
    "aws-amplify": "^5.3.3",
    "aws-sdk": "^2.1408.0",
    "axios": "^1.4.0",
    "expo": "~48.0.18",
    "expo-image-manipulator": "~11.1.1",
    "expo-image-picker": "~14.1.1",
    "expo-linear-gradient": "~12.1.2",
    "expo-status-bar": "~1.4.4",
    "react": "18.2.0",
    "react-native": "0.71.8",
    "react-native-paper": "^5.9.0",
    "react-native-responsive-screen": "^1.4.2"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true
}

OK, there’s nothing obviously wrong with your dependencies (although I’ve never used those aws dependencies, so I might be missing something there.)

I’m trying a simulator build on a test app with the above dependencies to see if I get the same error.

Do you by any chance have an ios directory in your app?

EDIT: FYI it builds fine for me

I don’t have any directory called ios.
Just in case, here are the instructions to use Amplify in react native:
https://docs.amplify.aws/start/getting-started/setup/q/integration/react-native/#create-a-new-project

EDIT: Wow that’s strange. I was able to build successfully until I added these dependencies.

If I install those dependencies like this (I am using yarn instead of npm, but that should not make a difference):

yarn add aws-amplify amazon-cognito-identity-js @react-native-community/netinfo @react-native-async-storage/async-storage

then it installs later versions of @react-native-async-storage/async-storage and @react-native-community/netinfo than you had specified in your dependencies:

diff --git package.json package.json
index 4fee6e9..c1a7958 100644
--- package.json
+++ package.json
@@ -9,8 +9,8 @@
     "web": "expo start --web"
   },
   "dependencies": {
-    "@react-native-async-storage/async-storage": "1.17.11",
-    "@react-native-community/netinfo": "9.3.7",
+    "@react-native-async-storage/async-storage": "^1.18.2",
+    "@react-native-community/netinfo": "^9.4.1",
     "amazon-cognito-identity-js": "^6.3.1",
     "aws-amplify": "^5.3.3",
     "aws-sdk": "^2.1408.0",

Did you have to run amplify init before you got the error?

Also, can you try a simulator build?

I built with the sim-dev profile as defined below:

eas.json

  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "sim-dev": {
      "extends": "development",
      "ios": {
        "simulator": true
      }
    },