Enable strict mode for JavaScript projects
mainIn TypeScript, envsafe returns a Readonly<T> which prevents accessing undefined properties. In vanilla JavaScript, you can still access undefined environment variables. To prevent this, enable strict: true in the options object. This wraps the result in Object.freeze and a Proxy that throws an error if you attempt to access a property that was not defined in your schema.
import { envsafe, str } from 'envsafe';
export const browserEnv = envsafe(
{
MY_ENV: str(),
},
{
strict: true,
},
);