chihab / dotenv-run

Seamlessly load environment variables. Supports cli, esbuild, rollup, vite, webpack, angular. ESM and Monorepos.
238 stars 17 forks source link

@ngx-env not loading variables #72

Closed russelporosky closed 7 months ago

russelporosky commented 7 months ago

When I run npm run start, it appears that my .env.local file is being loaded (it's listed under "Environment Files"), but the values in it aren't shown like in the demos, and they aren't loaded in the app. If I console.log(import.meta.env), only the built in ones appear:

{
  BASE_URL: '/',
  MODE: 'development',
  DEV: true,
  PROD: false,
  SSR: true
}

I've modified env.d.ts to have the keys I want (APP_BASE_URL: string for example).

I am using the Angular project variation - so my source code is actually in a projects folder and not the default src folder.

chihab commented 7 months ago

Could you set the "unsecure" flag to true in your angular.json file and share the output please?

image

chihab commented 7 months ago

Does console.log(import.meta.env.YOUR_ENV_VAR) display the environment variable?

Actually @ngx-env/builder (through esbuild) replaces "import.meta.env.YOUR_ENV_VAR" in your source code by the actual values from your environment. The expression import.meta.env itself is not replaced or mutated.

russelporosky commented 7 months ago

unsecure doesn't seem to do anything - what was expected?

Console logging the specific var doesn't display anything, same as trying to use it in a component.

chihab commented 7 months ago

Could you please share the output in the console of npm start?

russelporosky commented 7 months ago

Figured it out by accident. I used the same var names the demo uses and it worked, and then I realized they have to start with NG_APP_ (although _NG_APP works as well - maybe it just needs that text anywhere in the name).

That should be documented. I wasted a goodish amount of time expecting APP_API_URL and FIREBASE_STORAGE to work.

chihab commented 7 months ago

Sorry for that, still restructing the docs and working on https://dotenv.run.

The original @ngx-env/builder documentation is here https://github.com/chihab/dotenv-run/tree/main/packages/angular