From bc99d302755084d8dd7d978923049a9d57721db3 Mon Sep 17 00:00:00 2001 From: David Molinero Date: Mon, 11 Jan 2021 16:13:38 +0000 Subject: [PATCH] Fix esbuild warning dynamic require --- packages/node/src/integrations/modules.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/node/src/integrations/modules.ts b/packages/node/src/integrations/modules.ts index 0b15ef1532cf..df8bcc16d261 100644 --- a/packages/node/src/integrations/modules.ts +++ b/packages/node/src/integrations/modules.ts @@ -4,12 +4,21 @@ import { dirname, join } from 'path'; let moduleCache: { [key: string]: string }; +/** Extract information about paths */ +function getPaths(): string[] { + try { + return require.cache ? Object.keys(require.cache as Record) : []; + } catch (e) { + return []; + } +} + /** Extract information about package.json modules */ function collectModules(): { [name: string]: string; } { const mainPaths = (require.main && require.main.paths) || []; - const paths = require.cache ? Object.keys(require.cache as Record) : []; + const paths = getPaths(); const infos: { [name: string]: string; } = {};