chihab / dotenv-run

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

Angular 17 support #61

Closed PR4SAN closed 8 months ago

PR4SAN commented 10 months ago

With angular 17 this doesn't work and throws an error of Error: Schema validation failed with the following errors: Data path "" must have required property 'main'.

fsegurai commented 10 months ago

Yeah, got same error

chihab commented 9 months ago

In angular.json

build target

-"browser": "src/main.ts",
+"main": "src/main.ts",

serve target

-"buildTarget": "ng-app17:build:production"
+"browserTarget": "ng-app17:build:production"
-"buildTarget": "ng-app17:build:development"
+"browserTarget": "ng-app17:build:development"

image

image

Let me know if that works for you please.

Note that it will use the webpack builder which @ngx-env/builder is built on top of. There are still issues with using the esbuild plugins, once stable and enough documented, I'll release a new v17 compatible with vite and esbuild.

fsegurai commented 9 months ago

@chihab the workaround provided did the trick 😄 Thanks for your time and assistance. Look forward to the new version 🥇 👍🏼

chihab commented 9 months ago

Could you give npx ng add @ngx-env/builder@17.0.0-alpha.0 a try?

Make sure your build architect target has "builder": "@ngx-env/builder:application".

fsegurai commented 9 months ago

@chihab I tested the command provided npx ng add @ngx-env/builder@17.0.0-alpha.0 and no manual configuration nor further actions were required. I was able to use the environment variables 👍🏼 The build architect target property in the angular.json file was automatically updated to @ngx-env/builder:application

meteoiker commented 8 months ago

The latest available version of @ngx-env/core is 16.1.3 depending on Angular 16. I also cannot see updated code in the repository so for the moment I cannot update to angular version 17 until this package is updated. Does this code need more work for Angular 17 support or is simply a dependency update?

chihab commented 8 months ago

@ngx-env/core@16 should work with Angular 17 but its peer dep indicates ^16 so you should have a peer dep missing issue but if you force, it should work, in theory.

Now, I would suggest not to use @ngx-env/core mainly because the good practice is not put the process.env in the template nor in the component code but rather reference it in your angular environment files (or any configuration file).

https://github.com/chihab/ngx-env?tab=readme-ov-file#use-processenv-or-importmetaenv-inside-environmentts-files

meteoiker commented 8 months ago

Thank you @chihab . I was using the env pipe and migrated everything as you said and removed the dependency. Everything works.