Facing an Angular dilemma with environment.ts and Netlify’s .env variable. The core issue: my Angular 16 app isn’t reading the .env variable set on netlify as I’m using environment.ts and I’ve tried process.env.API_KEY with the variables set on netlify but it doesn’t see it. Connected via GitHub to Netlify, but pushing to the repo updates Netlify—credentials and all. How do I manage this without leaking credentials on GitHub? Tried dotenv in Angular, but the polyfills and webpack have their own agenda. Any cleaner solutions out there?
import { environment } from '../environments/environment';
import 'dotenv/config';
const uri = process.env.API_URL || 'default-api-url';
const adminSecret = process.env.HASURA_ADMIN_SECRET || 'default-admin-secret';
The above isn’t the final code, I’ve played around and change different variables and imports etc so its just one of the many attempts. Looking for a smoother path without causing build system chaos.
I think as long as it reads the API_URL or the HASURA_ADMIN_SECRET variables given then it should be all good. Like a console.log that shows the values set from Netlify Environment Variables.
Below are the necessary variables in order for the deployment to complete itself.
NODE_VERSION:18
NPM_FLAGS: --force
I think you need to configure target specific requirements since your environment.ts says production: false: Angular - Building and serving Angular apps and in your environment files, you should probably use the value asprocess.env['ENV'] instead of adding the strings the way you’ve done.