EAS build can't seem to find my environment file

Is it possible to inspect what files are getting transferred to EAS? In my app.config.js I am switching between different .env files based on which mode is used (preview or production).

It looks like this:

import * as dotenv from 'dotenv'
import fs from 'fs'

const envPath = process.env.APP_ENV
  ? `.env.${process.env.APP_ENV}`
  : '.env.development'

if (!fs.existsSync(envPath)) {
  throw new Error(
    `No ${envPath} file found. Please create one within the root directory of this project.`
  )
}

dotenv.config({ path: envPath })

export default ({ config }) => {
  return {
    ...config,
    extra: {
      API_KEY: process.env.API_KEY,
      // And more...
    }
  }
}

When publishing or building it finds the .env.preview file, but on EAS build I get the following:

I don’t really know what to do and why it can’t find my .env.preview file.

If file is gitignored it won’t be uploaded to eas

Hey wkozyra,

Thank you again for the quick answer. Your document helped me to debug further and the .env files aren’t gitignored, but with eas build inspect I can see the files are indeed in the archive.

So the problem should be in finding the file on the server. I have updated the pathname, going to trigger a new build to test it.

It worked! I was using the fs module wrong:

import * as dotenv from 'dotenv'
import fs from 'fs'
import path from 'path'

const envPath = process.env.APP_ENV
  ? `.env.${process.env.APP_ENV}`
  : '.env.development'

const filePath = path.join(__dirname, envPath)

if (!fs.existsSync(filePath)) {
  throw new Error(
    `No ${envPath} file found. Please create one within the root directory of this project.`
  )
}

dotenv.config({ path: envPath })

export default ({ config }) => {
  return {
    ...config,
    extra: {
      API_KEY: process.env.API_KEY,
      // and more
    }
  }
}

Marking this as answer because the eas build:inspect helped me tracking my issue.