'EAS build can't find aws-exports
I have an Expo project with AWS Amplify. I'm currently using EAS from Expo to deploy on mobile.
Pretty often I run on this error:
❌ Metro encountered an error:
Unable to resolve module ./src/aws-exports from /Users/expo/workingdir/build/App.tsx:
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)
11 | import Amplify from 'aws-amplify';
> 12 | import awsconfig from './src/aws-exports';
15 | Amplify.configure(awsconfig);
But, I do have the file aws-exports
and I can run locally fine. Sometimes I can build without problems. Didn't figure yet a pattern about when it happens or not.
I suspect it may be something related to gitignore
(I think that EAS may check it before uploading to server). I already tried to run the command with --clear-cache
and I didn't notice any effect.
Any suggestions about what can I do? :)
Solution 1:[1]
The aws-exports.js
changes way too often at times and you would need to remember to always update it if you go the base64 route. Another way, if not better way, is to create a .easignore
file and copy the contents of .gitignore and then exclude the aws-exports.js
file.
EAS will use .easignore
instead of the .gitignore
and you never have to do anything again.
Solution 2:[2]
EAS build has access to same version of your code as it is on git. Best option would be:
- encode aws-exports.js file to base64
- add encoded value as EXPO secret env variable
- decode that env variable back to aws-exports.js during pre-install phase
"eas-build-pre-install"
npm script. i.e.:
"scripts":{
"eas-build-pre-install": "echo $AWS_EXPORTS | base64 -d > ./src/aws-exports.js",
...
}
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 | orome |
Solution 2 | v.nikopolidi |