chihab / dotenv-run

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

blank defaultConfiguration throws Webpack warnings during build #5

Closed zencm closed 2 years ago

zencm commented 3 years ago

I added this neat package (which works nicely in another project) to an existing project which has been migrated to angular 12 in the past.

When running ng serve, i.e. using the default environment, we get a slew of these warnings, without it affecting the app or .env functionality otherwise:

Warning: DefinePlugin
Conflicting values for 'process.env.NODE_ENV'

Apparently the angular.json has an empty "defaultConfiguration": "" line and is also not invoked with a specific environment by default. Production builds do not have this issue, likely as that has a specific environment.

The readme says that NODE_ENV should default to 'development', but in this case it is undefined, probably because { browserTarget.configuration is also undefined. I changed dev-server/index.js to default to 'development': { env: browserTarget.configuration || 'development' }.

…but I am not sure whether he warning is the intended behavior or our project setup is somewhat broken.

JohnnyTMD commented 3 years ago

Same issue for me also

chihab commented 2 years ago

On version 2.0.0 NODE_ENV usage has been removed because it is confusing since it is conflicting with webpack builder configuration set by the Angular CLI. NODE_ENV has been replaced with NG_APP_ENV which is set to NODE_ENV value by default but can be overridden.

Usge

NG_APP_ENV=development npm start

I would not recommend using NODE_ENV=development for the same reason mention about Angular CLI internals.

Does that make sense to you? Let me know if there is a common use case I didn't think of.