Skip to content

Commit 26a1c7f

Browse files
Timermrmckeb
andauthored
Fix dotenv file loading order (#9037)
* Fix dotenv file loading order * tests: fix failing env tests * tests: fix more failing tests Co-authored-by: Brody McKee <mrmckeb@hotmail.com>
1 parent d97fbad commit 26a1c7f

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

docusaurus/docs/adding-custom-environment-variables.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ REACT_APP_NOT_SECRET_CODE=abcdef
132132

133133
Files on the left have more priority than files on the right:
134134

135-
- `npm start`: `.env.development.local`, `.env.development`, `.env.local`, `.env`
136-
- `npm run build`: `.env.production.local`, `.env.production`, `.env.local`, `.env`
135+
- `npm start`: `.env.development.local`, `.env.local`, `.env.development`, `.env`
136+
- `npm run build`: `.env.production.local`, `.env.local`, `.env.production`, `.env`
137137
- `npm test`: `.env.test.local`, `.env.test`, `.env` (note `.env.local` is missing)
138138

139139
These variables will act as the defaults if the machine does not explicitly set them.

packages/react-scripts/config/env.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ if (!NODE_ENV) {
2525
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
2626
const dotenvFiles = [
2727
`${paths.dotenv}.${NODE_ENV}.local`,
28-
`${paths.dotenv}.${NODE_ENV}`,
2928
// Don't include `.env.local` for `test` environment
3029
// since normally you expect tests to produce the same
3130
// results for everyone
3231
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
32+
`${paths.dotenv}.${NODE_ENV}`,
3333
paths.dotenv,
3434
].filter(Boolean);
3535

packages/react-scripts/fixtures/kitchensink/template/integration/env.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ describe('Integration', () => {
3131
'production'
3232
);
3333
expect(doc.getElementById('feature-file-env-x').textContent).toBe(
34-
'x-from-production-env'
34+
'x-from-original-local-env'
3535
);
3636
} else {
3737
expect(doc.getElementById('feature-file-env').textContent).toBe(
3838
'development'
3939
);
4040
expect(doc.getElementById('feature-file-env-x').textContent).toBe(
41-
'x-from-development-env'
41+
'x-from-original-local-env'
4242
);
4343
}
4444
});

0 commit comments

Comments
 (0)