EAS build fails with simple boilerplate AWS Amplify

Wow, for some reason now using a simulator build I was able to build :thinking:.
I hope this helps to discover what the problem is.

hmmm… OK I’m trying a development build now.

What were you building when you got the error? A production build?

EDIT: OK, the build failed. Strange.

But if I run npx expo-doctor now I get this:

% npx expo-doctor
✔ Check package.json for common issues
✔ Validate global prerequisites versions
✔ Validate Expo Config
✔ Check for conflicting global packages in project
✔ Check for incompatible packages
✔ Verify prebuild support package versions are compatible
✖ Check compatible dependency versions for the installed Expo SDK

Detailed check results:

Some dependencies are incompatible with the installed expo version:
  @react-native-async-storage/async-storage@1.18.2 - expected version: 1.17.11
  @react-native-community/netinfo@9.4.1 - expected version: 9.3.7
Your project may not work correctly until you install the correct versions of the packages.
Install individual packages by running npx expo install @react-native-async-storage/async-storage@1.17.11 @react-native-community/netinfo@9.3.7
Found outdated dependencies
Advice: Use 'npx expo install --check' to review and upgrade your dependencies.

One or more checks failed, indicating possible issues with the project.

So I ran npx expo install --check which reverted those two deps back to what you had originally.

Trying the build again.

What I was doing was:
eas build -p ios
I don’t have much experience with expo building but that’s how I’ve built apps in the past. Now I tried again to eas build -p ios after the successful simulator build and I got the same error.

Tried expo-doctor but I got the same result,

Didn’t find any issues with the project!

I already have async-storage@1.17.11 and netinfo@9.3.7

hmmm… actually I see that although I got those “duplicate method” messages they are warnings and not errors. So I checked the simulator build and I see them there too. So actually the build succeeds, but the warnings seem like they could be problematic:

⚠️  ld: duplicate method '+moduleName' in
┌─[category]: ExpoBridgeModule-575d67561a3a054d08f619017c5a94e2.o ExpoModulesCore/libExpoModulesCore.a
└─[class]: ExpoBridgeModule-25b2959fc712d2326eb8de55d650b460.o ExpoModulesCore/libExpoModulesCore.a

⚠️  ld: duplicate method '+moduleName' in
┌─[category]: DevMenuPreferences-20469d9e1a40f3105641807fa6f55c56.o expo-dev-menu/libexpo-dev-menu.a
└─[class]: DevMenuPreferences-cd9226553df9e98fb3edf845ba04440e.o expo-dev-menu/libexpo-dev-menu.a

› Compiling deps » AppDelegate.mm

› Linking   deps » deps

⚠️  ld: duplicate method '+moduleName' in
┌─[category]: ExpoBridgeModule-575d67561a3a054d08f619017c5a94e2.o ExpoModulesCore/libExpoModulesCore.a
└─[class]: ExpoBridgeModule-25b2959fc712d2326eb8de55d650b460.o ExpoModulesCore/libExpoModulesCore.a

⚠️  ld: duplicate method '+moduleName' in
┌─[category]: DevMenuPreferences-20469d9e1a40f3105641807fa6f55c56.o expo-dev-menu/libexpo-dev-menu.a
└─[class]: DevMenuPreferences-cd9226553df9e98fb3edf845ba04440e.o expo-dev-menu/libexpo-dev-menu.a

That’s equivalent to:

eas build -p ios --profile production

OK, then it seems the “main.jsbundle does not exist” error was not caused by the duplicate methods. Can you check the Xcode logs for any other relevant error messages?

EDIT:

The production build works for me (but still with the duplicate method warnings).

That’s strange, only the production build doesn’t work for me

Now I opened the Xcode logs and I’m seeing the issue is related to aws-exports:

error Unable to resolve module ./src/aws-exports from /Users/expo/workingdir/build/hooks.js:

None of these files exist:

  • src/aws-exports(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
  • src/aws-exports/index(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
    e[0m e[90m 2 |e[39m e[36mimporte[39m { e[33mSecretsManagere[39me[33m,e[39m confige[33m,e[39m e[33mCredentialse[39me[33m,e[39m e[33mCognitoIdentityServiceProvidere[39m } e[36mfrome[39m e[32m’aws-sdk’e[39me[33m;e[39me[0m
    e[0m e[90m 3 |e[39m e[36mimporte[39m { e[33mAmplifye[39me[33m,e[39m e[33mAuthe[39me[33m,e[39m e[33mAWSMobileCliente[39m } e[36mfrome[39m e[32m’aws-amplify’e[39me[33m;e[39me[0m
    e[0me[31me[1m>e[22me[39me[90m 4 |e[39m e[36mimporte[39m awsconfig e[36mfrome[39m e[32m’./src/aws-exports’e[39me[33m;e[39me[0m
    e[0m e[90m |e[39m e[31me[1m^e[22me[39me[0m
    e[0m e[90m 5 |e[39me[0m
    e[0m e[90m 6 |e[39me[0m
    e[0m e[90m 7 |e[39m e[33mAmplifye[39me[33m.e[39mconfigure(awsconfig)e[33m;e[39me[0m.

So now I modified my .gitignore adding ! in front of aws-exports, I think that makes an exception for the rule. I’m building now :crossed_fingers::

#amplify-do-not-edit-begin

amplify/#current-cloud-backend

amplify/.config/local-*

amplify/logs

amplify/mock-data

amplify/mock-api-resources

amplify/backend/amplify-meta.json

amplify/backend/.temp

build/

dist/

node_modules/

!aws-exports.js

OK, the problem is it’s not a good idea to commit these to your Git repository.

What you can do instead is something like this (assuming you’re on macOS or Linux):

cat aws-exports.js | bzip2 -9 | base64 -o -

This will output a Base64-encoded string containing the compressed aws-exports.js.

You can create a project secret called e.g. AWS_EXPORTS and set the value to the Base64-encoded string.

Then in the scripts section of package.json you can add a script called eas-build-pre-install with a value of something like this:

"echo \"$AWS_EXPORTS\" | base64 -d | bzip2 -dc > aws-exports.js"

See notbrent’s comment in this thread (comment number 4) for more info and also a way to do use .easignore instead.

Oh nice to know this safer way of doing it. But my github repo is private, so it shouldn’t be an issue unless someone can get access to it, or it might be vulnerable in other ways?

I’ll try your method anyways, looks like a much better practice.
But finally I was able to build this app, so I’m happy knowing that’s finally working :tada:.

Thank you very much for your help :slight_smile:

1 Like

It’s best not to rely on that. Maybe someone will get access to your GitHub account. If they do you don’t want them to automatically have access to your AWS credentials.

1 Like

Ok but now that I was able to build the app, I shared it using TestFlight and the app crashes as soon as it opens. But the same app works perfectly when I’m running expo simulator in my laptop and my iphone.
I can’t see any logs so it’s hard to know what is the problem. Would you have some idea?

Are you running Expo Go or a development build on the Simulator?

You could try running with:

npx expo start --no-dev --minify

This bundles the JavaScript in the same way as on production. Hopefully it crashes like that and you should get some more information about the problem.

Also check the device logs from your phone.

See also:

I was running Expo Go, now I used npx expo start --no-dev --minify and the app works perfectly, there must be a difference with a production build because the latter doesn’t work.

It seems to use device logs I need to have X-Code, currently I have only X-Code Server Builder.
I will have to free some more HD space X-Code, I have only 11GB and if I try to install it it says there is no enough space.

Maybe try Sentry

Unfortunately, Xcode is a beast

Thank you very much. Installed sentry and solved the problem.

Finally I’m able to open the app, my only problem now is that it seems the app doesn’t connect well to AWS, I see that the API request made from the production build don’t include the token AWS generates so they get rejected. But when I do the same in my expo simulator the token gets generated and the request is successful.
Do I need to do the something else so the production build works well with AWS? Didn’t found any additional step in AWS documentation.

Sorry, I don’t know. Perhaps you can contact the AWS Amplify project?

1 Like