Parcel: RFC: dotenv support should not use NODE_ENV

Created on 1 Aug 2018  路  6Comments  路  Source: parcel-bundler/parcel

馃挰 RFC

Currently the dotenv support uses process.env.NODE_ENV to decide what .env file to load in src/utils/env.js

This has come up a few times across the nodejs ecosystem where users are setting NODE_ENV without being aware of the consequences.

Rather than making a PR to change it I thought it might be best to raise it as an rfc first and maintainers could come up with some suggestion in the event they agree with this requested change.

PARCEL_ENV or BUILD_ENV or has someone got something a lot better?

馃敠 Context

A lot of code across the node ecosystem uses if(process.env.NODE_ENV !== 'production')
This is important because it means that we should not depend on NODE_ENV when trying to load a staging or other target environment that we don't want to behave like a development environment.

RFC Stale

Most helpful comment

+1 here, I want to run everything on staging as if it were production, just with some different env variables. So NODE_ENV=production is a must. I have a bunch of variables - I would love an option like parcel build --env-file .env.staging index.html

All 6 comments

Seem more and more ppl having this issue. It's a won't fix as mentioned in #1476 but I sincerely hope this RFC accepted in v2

1476 has been fixed a long while ago and should only fallback to a default.

1476 has been fixed a long while ago and should only fallback to a default.

Thank you very much for pointing out. I just noticed that it was fixed in v1.9.3.

I've been struggling with this setting too.

When I build using NODE_ENV=production my basic React helloworld comes in at 117.88 KB. If i run NODE_ENV=staging the helloworld bundle comes in at 249.77 KB (say what?).

There appears to be no easy way to create a fully minified build for a staging environment for React. I think React is at fault here of using NODE_ENV. Parcel fixes that mistake by automatically setting NODE_ENV=production when it makes sense.

However right now creating A/B tests or minified builds for non-production environments requires me to generate .env.production files dynamically. Not ideal.
Edit: discovered Parcel includes the https://github.com/motdotla/dotenv-expand library, allowing you to just set env variables while keeping NODE_ENV=production.

The fix seems simple: allow some other means to load a .env.{...} file.

I like the suggestion of @martell; let's not promote the use of NODE_ENV everywhere.

A less invasive option could be an override like parcel build --env=test index.html.

+1 here, I want to run everything on staging as if it were production, just with some different env variables. So NODE_ENV=production is a must. I have a bunch of variables - I would love an option like parcel build --env-file .env.staging index.html

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

devongovett picture devongovett  路  49Comments

jpsc picture jpsc  路  81Comments

jpergler picture jpergler  路  59Comments

bbugh picture bbugh  路  84Comments

WayneHiller picture WayneHiller  路  51Comments