From aee8fda98ac5ab59afe3c6c139b21aec0edc6239 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Fri, 3 Jul 2020 10:56:28 +0200 Subject: [PATCH] fix: make Node.js environment detection robust w.r.t. JSDOM (#6148) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously Node.js was detected by the lack of `global.document` which doesn’t work in case JSDOM is being used in Node.js. Instead, we now detect `process.versions.node`, like here: https://github.com/MatthewSH/is-node/commit/426943ae936536f9c2fd10fd58a9a46b59470097#diff-168726dbe96b3ce427e7fedce31bb0bc. Fixes #6147. --- src/environment.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/environment.ts b/src/environment.ts index 0d2a7a1f125cb..25c59864eb498 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -14,4 +14,8 @@ * limitations under the License. */ -export const isNode = typeof document === 'undefined'; +export const isNode = !!( + typeof process !== 'undefined' && + process.versions && + process.versions.node +);