Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
renatomcamilio opened this issue Sep 29, 2020 · 1 comment
Open

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

renatomcamilio opened this issue Sep 29, 2020 · 1 comment

Comments

@renatomcamilio
Copy link

renatomcamilio commented Sep 29, 2020

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?
@jeffbski
Copy link
Owner

@renatomcamilio Thanks for reaching out.

Regarding your questions:

  1. Yes, this was for the build step
  2. yes, I assume you are wanting to silence the warning logs.

When you create your logic, just set warnTimeout: 0 and this should silence all of those logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants