diff --git a/packages/js/src/utils/package-json/get-npm-scope.ts b/packages/js/src/utils/package-json/get-npm-scope.ts index 1e018f5528..61da6228c7 100644 --- a/packages/js/src/utils/package-json/get-npm-scope.ts +++ b/packages/js/src/utils/package-json/get-npm-scope.ts @@ -11,7 +11,9 @@ export function getNpmScope(tree: Tree): string | undefined { return nxJson.npmScope; } - const { name } = readJson<{ name?: string }>(tree, 'package.json'); + const { name } = tree.exists('package.json') + ? readJson<{ name?: string }>(tree, 'package.json') + : { name: null }; if (name?.startsWith('@')) { return name.split('/')[0].substring(1); diff --git a/packages/workspace/src/utilities/get-import-path.ts b/packages/workspace/src/utilities/get-import-path.ts index dba9eb24e8..b68447f22f 100644 --- a/packages/workspace/src/utilities/get-import-path.ts +++ b/packages/workspace/src/utilities/get-import-path.ts @@ -17,7 +17,9 @@ function getNpmScope(tree: Tree) { return nxJson.npmScope; } - const { name } = readJson<{ name?: string }>(tree, 'package.json'); + const { name } = tree.exists('package.json') + ? readJson<{ name?: string }>(tree, 'package.json') + : { name: null }; if (name?.startsWith('@')) { return name.split('/')[0].substring(1);