Skip to content

Commit

Permalink
check if mod.paths is defined before using it
Browse files Browse the repository at this point in the history
  • Loading branch information
iliapolo committed Apr 29, 2020
1 parent 6784dc3 commit 0f4d5b7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/@aws-cdk/core/lib/private/runtime-info.ts
Expand Up @@ -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 {
Expand Down

0 comments on commit 0f4d5b7

Please sign in to comment.