This is a meta issue to discuss the handling of .env support for Node in Parcel.
Currently, we don't do any global variable replacement for node (--target=node). This means that process.env is left as-is in the built code. This could be quite confusing as, for the browser, process.env is entirely build-time, but for node, it's entirely runtime.
Personally, my thoughts are that for node development, it would be hugely useful if process.env variables were replaced _if_ a .env.XX environment file exists, and even then, only replace the variables that are defined. This would allow for a one line developer experience node build/index.js, though also allow servers/system environment variables to be used if none were specified.
@devongovett @DeMoorJasper @brandon93s @fathyb
Environment variables in node.js should probably always be declared on runtime and be ignored on built-time.
What would be the exact use-case for this?
Didn鈥檛 we add support for .env back in #258?
@davidnagli Yes, you did. But, as the issue states, it's currently inconsistent. --target=node doesn't support .env files.
EDIT: I guess what I'm really asking is: is this ok & is this what most would expect?
@DeMoorJasper A use case for build-time environment variables in Node is inlining configuration values that can not be set at runtime because you are not in control of that. E.g. I'm trying to use Parcel to build AWS Lambda functions for Netlify written in Typescript, but they can only be configured by baking in the variables at build-time as that is the only thing Netlify lets you set up. I could also imagine e.g. building an Electron app that needs api keys inserted for analytics or error reporting services.
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.
Most helpful comment
@davidnagli Yes, you did. But, as the issue states, it's currently inconsistent.
--target=nodedoesn't support.envfiles.EDIT: I guess what I'm really asking is: is this ok & is this what most would expect?