From b7afc9e47ea2847dc23371989f361ab8cffa44f6 Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Mon, 31 Jul 2023 10:32:31 +0200 Subject: [PATCH] fix(nextjs): fix build for yarn pnp --- packages/next/src/executors/build/build.impl.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/next/src/executors/build/build.impl.ts b/packages/next/src/executors/build/build.impl.ts index eb0678c66f76b..bcb45f5644a28 100644 --- a/packages/next/src/executors/build/build.impl.ts +++ b/packages/next/src/executors/build/build.impl.ts @@ -1,8 +1,11 @@ import 'dotenv/config'; import { + detectPackageManager, ExecutorContext, + getPackageManagerVersion, logger, readJsonFile, + workspaceRoot, writeJsonFile, } from '@nx/devkit'; import { createLockFile, createPackageJson, getLockFileName } from '@nx/js'; @@ -53,7 +56,14 @@ export default async function buildExecutor( process.env.NX_NEXT_OUTPUT_PATH ??= outputPath; const args = createCliOptions({ experimentalAppOnly, profile, debug }); - const command = `npx next build ${args.join(' ')}`; + const isYarnBerry = + detectPackageManager() === 'yarn' && + gte(getPackageManagerVersion('yarn', workspaceRoot), '2.0.0'); + const buildCommand = isYarnBerry + ? `yarn next build ${projectRoot}` + : 'npx next build'; + + const command = `${buildCommand} ${args.join(' ')}`; const execSyncOptions: ExecSyncOptions = { stdio: 'inherit', encoding: 'utf-8',