From 82e8586c6c9dfc4fab16900f4d1a61c292593d98 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Wed, 28 Aug 2024 15:08:04 -0400 Subject: [PATCH] fix(core): fixes an issue where using "node:test" results in infinite loop (#27685) This PR fixes an issue with `node:test` not being recognized as a built-in Node module, and since it is not in `node_modules` with a resolvable `package.json`, it hits an infinite loop. ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes # (cherry picked from commit e28de09c40d71f7063fb75e77c2df18027f533b1) --- .../build-dependencies/target-project-locator.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/nx/src/plugins/js/project-graph/build-dependencies/target-project-locator.ts b/packages/nx/src/plugins/js/project-graph/build-dependencies/target-project-locator.ts index af2890d22cdd8..5a142c0b78448 100644 --- a/packages/nx/src/plugins/js/project-graph/build-dependencies/target-project-locator.ts +++ b/packages/nx/src/plugins/js/project-graph/build-dependencies/target-project-locator.ts @@ -34,6 +34,13 @@ const defaultNpmResolutionCache: NpmResolutionCache = new Map(); const builtInModuleSet = new Set([ ...builtinModules, ...builtinModules.map((x) => `node:${x}`), + // These are missing in the builtinModules list + // See: https://github.com/nodejs/node/issues/42785 + // TODO(v20): We should be safe to use `isBuiltin` function instead of keep the set here (https://nodejs.org/api/module.html#moduleisbuiltinmodulename) + 'test', + 'node:test', + 'node:sea', + 'node:sqlite', ]); export function isBuiltinModuleImport(importExpr: string): boolean { @@ -364,7 +371,7 @@ export class TargetProjectLocator { packageJsonPath ?? resolveRelativeToDir(packageName, relativeToDir); let dir = dirname(pathOfFileInPackage); - while (dir !== parse(dir).root) { + while (dir !== dirname(dir)) { const packageJsonPath = join(dir, 'package.json'); try { const parsedPackageJson = readJsonFile(packageJsonPath);