zertosh / invariant

invariant
MIT License
1.22k stars 70 forks source link

Question: is `process.env` possibly undefined? #30

Closed aaronbeall closed 6 years ago

aaronbeall commented 6 years ago

This is more a question than an issue, sorry if there was a better place to ask this.

I noticed the code that accesses process.env.NODE_ENV. Isn't it possible that process itself could be undefined, leading to an error in strict mode?

BerkeleyTrue commented 6 years ago

In node, process and process.env are always defined.

If bundling for a different environment, it is standard practice to have the bundler inject a value for process.env.NODE_ENV.

For instance, if using webpack, you would use the webpack DefinePlugin to overwrite this lookup with a static value.

Or, like the readme says, use Envify if using Browserify as a bundler. Most bundling systems have a standard way of doing this.

The onus is on the consumer to make sure this is defined, not the package maintainer.