Skip to content

Commit 4aa0d9e

Browse files
authored
fix: restore compatibility with older create-react-app versions (#169)
* fix: backward compat for create-react-app polyfill * chore: add comment explaining create-react-app workaround * fix: process.env handling for react and vite
1 parent 8b6f625 commit 4aa0d9e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 7.4.1 (29/08/2023)
2+
* Fix 7.4.0 issues with `create-react-app` polyfill (#168)
3+
14
## 7.4.0 (21/08/2023)
25
* Do not use `process.env` by default in non-Node.js environments (#155)
36

env-var.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,19 @@ const from = (container, extraAccessors, logger) => {
5252
}
5353
}
5454

55+
/**
56+
* Makes a best-effort attempt to load environment variables in
57+
* different environments, e.g create-react-app, vite, Node.js
58+
* @returns Object
59+
*/
60+
function getProcessEnv () {
61+
/* istanbul ignore next */
62+
try {
63+
return process.env
64+
} catch (e) {
65+
return {}
66+
}
67+
}
68+
5569
/* istanbul ignore next */
56-
module.exports = from(typeof process === 'undefined' ? {} : process.env)
70+
module.exports = from(getProcessEnv())

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "env-var",
3-
"version": "7.4.0",
3+
"version": "7.4.1",
44
"description": "Verification, sanitization, and type coercion for environment variables in Node.js",
55
"main": "env-var.js",
66
"typings": "env-var.d.ts",

0 commit comments

Comments
 (0)