From d24f2ef021ae193280b8b55c74dc8a4653195299 Mon Sep 17 00:00:00 2001 From: Sam Verschueren Date: Thu, 10 Jan 2019 11:07:58 +0100 Subject: [PATCH] Import the `fs` module only in Node.js environments (#117) --- source/lib/utils/infer-label.ts | 5 ++++- source/lib/utils/node/fs.ts | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/source/lib/utils/infer-label.ts b/source/lib/utils/infer-label.ts index f9a680b..7e149ac 100644 --- a/source/lib/utils/infer-label.ts +++ b/source/lib/utils/infer-label.ts @@ -1,4 +1,4 @@ -import fs from './node/fs'; +import lazyFS from './node/fs'; import {CallSite} from 'callsites'; import * as isNode from 'is-node'; import isValidIdentifier from './is-valid-identifier'; @@ -17,6 +17,9 @@ export const inferLabel = (callsites: CallSite[]) => { return; } + // Load the lazy `fs` module + const fs = lazyFS(); + // Grab the stackframe with the `ow` function call const functionCallStackFrame = callsites[1]; diff --git a/source/lib/utils/node/fs.ts b/source/lib/utils/node/fs.ts index c301f8a..81a2bc7 100644 --- a/source/lib/utils/node/fs.ts +++ b/source/lib/utils/node/fs.ts @@ -1,4 +1,4 @@ import nodeRequire from './require'; -// Re-export the Node.js `fs` module to make sure it doesn't get bundled with front-end apps -export default nodeRequire('fs'); +// Re-export the Node.js `fs` module lazily to make sure it doesn't get bundled with front-end apps +export default () => nodeRequire('fs');