Environment variables accessed from process.env are considered undefined when running flow since the parser has no idea what is included inside of them.
How do I tell the parser that the env object exists and what keys does it include?
The contents of environment variables is like any other input given at runtime: it cannot be known statically. Therefore Flow must be conservative and force you to validate it with runtime checks. Here are two examples of runtime checks that work (copied from https://github.com/facebook/flow/issues/1192#issuecomment-299140919)
// throw
if (!process.env.FOO) throw new Error('FOO missing');
const foo = process.env.FOO;
// fall back
const bar = process.env.BAR || 'bar';
(foo: string); // ok!
(bar: string); // ok!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With