diff --git a/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts b/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts index 6b832e77bedce..73d7ebb05b838 100644 --- a/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts +++ b/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts @@ -288,7 +288,16 @@ module.exports = require('${mainFile}'); } function getPrefixLength(pattern: string): number { - return pattern.substring(0, pattern.indexOf('*')).length; + const prefixIfWildcard = pattern.substring(0, pattern.indexOf('*')).length; + const prefixWithoutWildcard = pattern.substring( + 0, + pattern.lastIndexOf('/') + ).length; + // if the pattern doesn't contain '*', then the length is always 0 + // This causes issues when there are sub packages such as + // @nx/core + // @nx/core/testing + return prefixIfWildcard || prefixWithoutWildcard; } function getTsConfigCompilerPaths(context: ExecutorContext): {