-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
warn user when using minified code outside of NODE_ENV 'production' #1075
Conversation
554e8d9
to
56592f7
Compare
This looks correct. (Have you checked whether it works?) |
56592f7
to
1d91a0c
Compare
@gaearon updated, is this what you meant by moving the check inline? Yes, I tested with this branch in a small app using redux and webpack with
|
function isCrushed() {} | ||
|
||
if (isCrushed.name !== 'isCrushed' && process.env.NODE_ENV !== 'production') { | ||
var warningMessage = 'You are utilzing minified code outside of NODE_ENV === \'production\'. ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're only using warningMessage
once, let's put it right inside the console.warn
call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that makes sense, updated.
7ee88ba
to
2da0dea
Compare
Thanks! |
2da0dea
to
dee4645
Compare
@gaearon sounds good thanks for such a great project and for the quick review/feedback! |
dee4645
to
76f6174
Compare
utilzing → utilizing. Or much better: using. |
76f6174
to
320a1c7
Compare
320a1c7
to
9b4754c
Compare
I'll tweak the error message anyway before merging, no worries! |
@gaearon I'm going to merge this in and tweak the message a tad on master. Please flog me appropriately if you disagree or don't like my tweaks :) |
warn user when using minified code outside of NODE_ENV 'production'
Thanks, please do! |
Out in 3.0.6, thanks! |
Hi |
I would use another ENV for swapping your configuration based on environment (
|
Yes, this is the reason we went with it. For example, React behaves much slower with |
Searched the source code and saw this now |
Well, it's being used in tons of projects now so we're not changing it anytime soon :-) |
If you don't want to deal with it you can use UMD builds. The minified build is envified for prod environment. |
I will use my own environment as suggested :) |
* create a function so that we can check if the function name has been altered by minification | ||
* if the function has been minified and NODE_ENV !== 'production', warn the user | ||
*/ | ||
function isCrushed() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line seems to behave differently in ie9 vs. modern browsers. Possible cause of #1311?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, fixed in 3.1.4.
We are using react with Java backend and this same error pops up. Why is that? |
It means you are minifying the code, but not envifying the CommonJS build. What do you build your JavaScript assets with? |
We are using Webpack, is this what we should do |
Yes. |
*/ | ||
function isCrushed() {} | ||
|
||
if (isCrushed.name !== 'isCrushed' && process.env.NODE_ENV !== 'production') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem right, if process.env.NODE_ENV
is not defined that doesn't necessarily indicate that I'm using minified code outside of production, or am I missing something? In our codebase we define NODE_ENV
without the "process.env" prefix but I can imagine lots of apps have no need to define it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From POV it was pretty surprising to see this pop up in production builds. Doesn't seem like something a library should try to enforce IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That comes from the Node universe, where process.env.NODE_ENV
is defined by default. process
is a global in Node. It is used in many libraries (React included) to define where development code is. Our module bundler (and most common setups) replaces the text process.env.NODE_ENV
with "production"
, which gets eliminated by an optimizer as dead code.
So, it would be a good idea to emulate the same behavior, even if you don't like it. There are some Babel plugins to make this easier (letting you use a global DEV). You're probably getting development builds of many other things for the same reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CommonJS build of Redux uses Node conventions. You can explicitly use the UMD builds in dist
folder if you’d rather avoid them.
We just went ahead with the same pattern React is using. If you use the CommonJS build of React and don’t envify process.env.NODE_ENV
, you are running a slow development version of React in production.
From http://facebook.github.io/react/docs/getting-started.html#using-react-from-npm:
We just follow the same convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. I suppose it makes sense for libraries to follow a convention for this and being loud about an inefficient build is good service. Thanks to both for your responses!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity though I would expect to see conditionals with process.env.NODE_ENV
or similar in the react codebase, but I don't. If I'm using webpack and requiring react how does defining it make the react build faster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They use DEV in their codebase, which is converted to the process.env format when they build the CommonJS version for publishing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting, got it!
@gaearon my attempt at #1029 . Likely still needs a bit of work but I wanted to get your opinion before i continued. thanks!