You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CRA's --target parameter only supports production value, not development, which results in console error with production build. As discussed here, custom env variable should be used for that. In our case REACT_APP_BUILD_ENV.
I also fixed build commands naming so they correspond to the current Gitlba CI configuration.
Based on the --target param. NODE_ENV and BUILD_ENV were automatically set. If we're going to define REACT_APP_BUILD_ENV before each build script, I'd suggest defining NODE_ENV before each build script as well and removing the --target completely. And so the packages/react-scripts/custom/config/env.js file can be then removed.
There is also a built-in environment variable called NODE_ENV. You can read it from process.env.NODE_ENV. When you run npm start, it is always equal to 'development', when you run npm test it is always equal to 'test', and when you run npm run build to make a production bundle, it is always equal to 'production'. You cannot override NODE_ENV manually. This prevents developers from accidentally deploying a slow development build to production.
So the --target param shouldn't affect it. Do you have any resource on that? Anyway it doesn't work for sure with --target stage as stated in the issue linked in the above description. There is even an error about production build in console when --target development is used.
So my conclusion to resolve the issue:
Is BUILD_ENV used for anything, how is it set and do we further need it?
We shouldn't set NODE_ENV manually, because it has always production value for yarn build and development for yarn start`.
We should remove --target as it clearly doesn't affect anything.
I don't agree with removing config/env.js. We define all environments used in code there and further export variables like isEnvDevelopment, etc. for convenience rather then always using process.env.REACT_APP_BUILD_ENV.
There is also a built-in environment variable called NODE_ENV. You can read it from process.env.NODE_ENV. When you run npm start, it is always equal to 'development', when you run npm test it is always equal to 'test', and when you run npm run build to make a production bundle, it is always equal to 'production'. You cannot override NODE_ENV manually. This prevents developers from accidentally deploying a slow development build to production.
So the --target param shouldn't affect it. Do you have any resource on that? Anyway it doesn't work for sure with --target stage as stated in the issue linked in the above description. There is even an error about production build in console when --target development is used.
So my conclusion to resolve the issue:
Is BUILD_ENV used for anything, how is it set and do we further need it?
We shouldn't set NODE_ENV manually, because it has always production value for yarn build and development for yarn start`.
We should remove --target as it clearly doesn't affect anything.
I don't agree with removing config/env.js. We define all environments used in code there and further export variables like isEnvDevelopment, etc. for convenience rather then always using process.env.REACT_APP_BUILD_ENV.
Only here - packages/react-scripts/custom/config/transformWebpackConfig.js and it just needs to be replaced with process.env.REACT_APP_BUILD_ENV.
Yes, make sense.
Yes, I agree. It was created by me but it has turned out to not be as a good feature as I initially thought it will 😄
Well the packages/react-scripts/custom/config/env.js was created by me and it can be safely removed. Don't misplace it with config/env.js, we definitely do not wanna remove that.
Good, I updated packages/react-scripts/custom/config/env.js and packages/react-scripts/custom/config/transformWebpackConfig.js to use REACT_APP_BUILD_ENV and removed --target flag.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
None yet
4 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CRA's
--target
parameter only supportsproduction
value, notdevelopment
, which results in console error with production build. As discussed here, custom env variable should be used for that. In our caseREACT_APP_BUILD_ENV
.I also fixed build commands naming so they correspond to the current Gitlba CI configuration.