If you have the file in .gitignore then by default it will not be uploaded to the build server when you run eas build.
There are a few solutions.
You could create a .easignore file that is basically a copy of your .gitignore file, except without the environment.ts file. Then eas will use that instead of .gitignore to decide what to ignore.
Another option is to use environment variables or secrets for this.