Skip to content

Commit 6c3926f

Browse files
committed
Add try/catch around reading package.json
1 parent a6794d9 commit 6c3926f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

library/agent/hooks/wrapRequire.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,14 @@ function patchPackage(this: mod, id: string, originalExports: unknown) {
189189
.flat();
190190

191191
// Read the package.json of the required package
192-
const packageJson = originalRequire(
193-
`${pathInfo.base}/package.json`
194-
) as PackageJson;
192+
let packageJson: PackageJson | undefined;
193+
try {
194+
packageJson = originalRequire(
195+
`${pathInfo.base}/package.json`
196+
) as PackageJson;
197+
} catch (error) {
198+
return originalExports;
199+
}
195200

196201
// Get the version of the installed package
197202
const installedPkgVersion = packageJson.version;

0 commit comments

Comments
 (0)