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

Cannot test my production configuration locally with NODE_ENV and npm start #436

Closed
fcaldera opened this issue Aug 14, 2016 · 3 comments
Closed

Comments

@fcaldera
Copy link

I have application settings that depends on the environment. You know, the classic config file that exports things in this way:

if (process.env.NODE_ENV === 'production') {
  // export production key/values here
} else {

}

I'm trying to test my production configuration locally by running
NODE_ENV=production npm start, however the NODE_ENV is always overwritten to development.

I ejected the code and realized that this is explicitly done at start.js script and webpack.DefinePlugin configuration, so I'm sure there were good reasons to do that. But, don't you guys think this is a very common pattern and something that probably other developers will try too?

I know #342 added support for custom variables and I could do something like REACT_APP_ENV=production npm start and change my code to rely on this variable instead, which is great, but I'm wondering if it wouldn't make this a little tricky, specially for people getting started with React.

@fcaldera fcaldera changed the title Cannot test my production configuration locally with npm start Cannot test my production configuration locally with NODE_ENV and npm start Aug 14, 2016
@gaearon
Copy link
Contributor

gaearon commented Aug 14, 2016

Why not build the app and test the built version?

@fcaldera
Copy link
Author

Yeah, that could work @gaearon. But what if I have others environments than development and production? For example a test environment. What if I want to run my app locally with all the test settings for some reason?

Probably a custom variable like REACT_APP_ENV would be suitable for this. We would just have to indicate people in the documentation that NODE_ENV is reserved mainly for optimisation and should not be used as reference to manage permanent application settings.

@gaearon
Copy link
Contributor

gaearon commented Aug 14, 2016

Yes, it seems like if you want more control, you’d have to use your own variables.

It’s very easy to mess up NODE_ENV and end up with slow version of React in production. I’ve seen this too many times and I would prefer the tool to force it to be correct depending on operation (start, test, build), even at the cost of some additional hassle for power users.

@gaearon gaearon closed this as completed Aug 14, 2016
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants