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; } = {};