Closed JonathanAsbury-Dovaxis closed 2 months ago
For a development build, you should be using the start script, not the build script.
Create-react-app also enforces NODE_ENV=build when building the app. This means you'll still have production variables enforced by create-react-app's react-scripts anyway, and is why react-app-rewired does the same thing.
From Create-react-app's documentation:
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.
You can override these variables by:
.env.production.local
to have the local version used for builds on your own machine, if production builds are always created in CI rather than locally, ordotenvx --env-file=.env.development -- yarn build
when wanting to create a development build instead of using the start scripts to have access to reloading/etc of development builds.Sorry for the delay in response - Github has apparently stopped notifying me of new issues being created. 😞
Thanks for the feedback. .env.production.local is a viable option for us. We currently have to build a version that get's pushed to our dev environment. Both .env.production.local and dotenvx look like solid options. Thanks for suggesting them! I really appreciate the follow-up!
Why are you forcing production on NODE_ENV in scripts/build.js During a development build, it causes all process.env values to exclusively load production values.