Skip to content

Commit

Permalink
fix: restore compatibility with older create-react-app versions (#169)
Browse files Browse the repository at this point in the history
* fix: backward compat for create-react-app polyfill

* chore: add comment explaining create-react-app workaround

* fix: process.env handling for react and vite
  • Loading branch information
evanshortiss authored Aug 28, 2023
1 parent 8b6f625 commit 4aa0d9e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 7.4.1 (29/08/2023)
* Fix 7.4.0 issues with `create-react-app` polyfill (#168)

## 7.4.0 (21/08/2023)
* Do not use `process.env` by default in non-Node.js environments (#155)

Expand Down
16 changes: 15 additions & 1 deletion env-var.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,19 @@ const from = (container, extraAccessors, logger) => {
}
}

/**
* Makes a best-effort attempt to load environment variables in
* different environments, e.g create-react-app, vite, Node.js
* @returns Object
*/
function getProcessEnv () {
/* istanbul ignore next */
try {
return process.env
} catch (e) {
return {}
}
}

/* istanbul ignore next */
module.exports = from(typeof process === 'undefined' ? {} : process.env)
module.exports = from(getProcessEnv())
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "env-var",
"version": "7.4.0",
"version": "7.4.1",
"description": "Verification, sanitization, and type coercion for environment variables in Node.js",
"main": "env-var.js",
"typings": "env-var.d.ts",
Expand Down

0 comments on commit 4aa0d9e

Please sign in to comment.