From adec3e0ef08a7c6695db7393a29e00bc829fee15 Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Tue, 7 Jun 2022 18:29:09 -0400 Subject: [PATCH] fix(core): custom executor package resolution should work when not using nx-plugin (#10624) --- packages/nx/src/utils/package-json.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/nx/src/utils/package-json.ts b/packages/nx/src/utils/package-json.ts index 25d627aa6ddb1..54550f1b7f1d8 100644 --- a/packages/nx/src/utils/package-json.ts +++ b/packages/nx/src/utils/package-json.ts @@ -110,10 +110,13 @@ export function readModulePackageJson( path: string; } { let packageJsonPath: string; + let packageJson: PackageJson; + try { packageJsonPath = require.resolve(`${moduleSpecifier}/package.json`, { paths: requirePaths, }); + packageJson = readJsonFile(packageJsonPath); } catch { const entryPoint = require.resolve(moduleSpecifier, { paths: requirePaths, @@ -125,14 +128,13 @@ export function readModulePackageJson( moduleRootPath = dirname(moduleRootPath); packageJsonPath = join(moduleRootPath, 'package.json'); } - } - const packageJson = readJsonFile(packageJsonPath); - - if (packageJson.name !== moduleSpecifier) { - throw new Error( - `Found module ${packageJson.name} while trying to locate ${moduleSpecifier}/package.json` - ); + packageJson = readJsonFile(packageJsonPath); + if (packageJson.name && packageJson.name !== moduleSpecifier) { + throw new Error( + `Found module ${packageJson.name} while trying to locate ${moduleSpecifier}/package.json` + ); + } } return {