Skip to content

NODE_ENV is always '' (empty string) in browser. #174

Open
@renatomcamilio

Description

@renatomcamilio

I ran into this issue where NODE_ENV is always !== "production", because when running in the browser window won't be undefined.

Check the code below:

const NODE_ENV = (typeof window === 'undefined' && process && process.env && process.env.NODE_ENV) ? process.env.NODE_ENV : '';

So, later on in the same file we reference it to decide whether to log warnings (using warnTimeout), and even in production builds we are seeing these logs:

if (NODE_ENV !== 'production' &&
typeof processOptions.dispatchMultiple !== 'undefined' &&
warnTimeout !== 0) {
// eslint-disable-next-line no-console
console.error(`warning: in logic for type(s): ${stringifyType(type)} - dispatchMultiple is always true in next version. For non-ending logic, set warnTimeout to 0`);
}

I have a couple questions regarding the way we define NODE_ENV here:

  1. why do we check for typeof window === 'undefined'? Is this just meant for the build/babel step?
  2. I'm using CRA, can't overwrite NODE_ENV. Do you have a suggestion how to approach this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions