diff --git a/packages/@aws-cdk/core/lib/private/runtime-info.ts b/packages/@aws-cdk/core/lib/private/runtime-info.ts index ac3d33046a74e..06d6815ff46d6 100644 --- a/packages/@aws-cdk/core/lib/private/runtime-info.ts +++ b/packages/@aws-cdk/core/lib/private/runtime-info.ts @@ -63,6 +63,15 @@ export function collectRuntimeInformation(): cxschema.RuntimeInfo { */ function findNpmPackage(fileName: string): { name: string, version: string, private?: boolean } | undefined { const mod = require.cache[fileName]; + + if (!mod.paths) { + // sometimes this can be undefined. for example when querying for .json modules + // inside a jest runtime environment. + // see https://github.com/aws/aws-cdk/issues/7657 + // potentially we can remove this if it turns out to be a bug in how jest implemented the 'require' module. + return undefined; + } + const paths = mod.paths.map(stripNodeModules); try {