Before posting your question, make sure you’ve read the documentation for both EAS Build & Submit.
- I’ve read the docs including Environment variables and secrets - Expo Documentation
If your Android or iOS build is failing- make sure you do your own research on the error message first before posting (this will give you a better understanding, and you might even find that someone else has already solved the issue!)
I’m using react-native-dotenv which adds a .env file to the root of my project. From reading the Xcode logs, it is clear that this file isn’t included in the build within EAS. Having read the docs on env variables, I tried implementing a constants.ts file which imports and exports my variables. I switched all imports from @exp
to @utilities/constants
. Before submitting a build via EAS again, I tried running the app locally via Xcode and I’m now getting this error which I can’t make sense of so I’m wondering if there is an additional step.
src/utilities/constants.ts: Property local of ExportSpecifier expected node to be of a type ["Identifier"] but instead got "StringLiteral"
Here is my constants.ts (with alternate values for the variables)
import {
VAR_1,
VAR_2,
VAR_3
} from '@env'
export {
VAR_1,
VAR_2,
VAR_3
}
Here is how the variables are being imported within my project:
import { VAR_1 } from '@utilities/constants'
Here is my babel.config.js:
module.exports = api => {
api.cache(true)
return {
presets: ['babel-preset-expo'],
plugins: [
[
'module:react-native-dotenv',
{
moduleName: '@env',
path: '.env'
}
],
[
'module-resolver',
{
extensions: ['.png', '.svg', '.ts', '.tsx'],
root: ['./'],
alias: {
'@types': './src/types',
'@utilities': './src/utilities'
}
}
]
]
}
}
And here is my environment variable types file env.d.ts:
declare module '@env' {
export const VAR_1: string
export const VAR_2: string
export const VAR_3: string
}
Even if I do get this to build, I’m concerned that this set still won’t work with EAS build because it is still reading from a .env rather than process.env.VAR_1, as an example. Any input would be greatly appreciated, thanks.