Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nextjs): Running nx build --configuration=development should not throw an error #17866

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions e2e/next/src/next.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { detectPackageManager, joinPathFragments } from '@nx/devkit';
import { capitalize } from '@nx/devkit/src/utils/string-utils';
import {
checkFilesDoNotExist,
checkFilesExist,
cleanupProject,
getPackageManagerCommand,
Expand Down Expand Up @@ -369,6 +370,21 @@ describe('Next.js Applications', () => {
checkFilesExist(`apps/${appName}/.next/build-manifest.json`);
}, 300_000);

it('should build in dev mode without errors', async () => {
const appName = uniq('app');

runCLI(
`generate @nx/next:app ${appName} --no-interactive --style=css --appDir=false`
);

checkFilesDoNotExist(`apps/${appName}/.next/build-manifest.json`);
checkFilesDoNotExist(`apps/${appName}/.nx-helpers/with-nx.js`);

expect(() => {
runCLI(`build ${appName} --configuration=development`);
}).not.toThrow();
}, 300_000);

it('should support --js flag', async () => {
const appName = uniq('app');

Expand Down
14 changes: 8 additions & 6 deletions packages/next/src/executors/build/build.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ export default async function buildExecutor(
});
}

createNextConfigFile(options, context);

copySync(join(projectRoot, 'public'), join(options.outputPath, 'public'), {
dereference: true,
});

// If output path is different from source path, then copy over the config and public files.
// This is the default behavior when running `nx build <app>`.
if (options.outputPath.replace(/\/$/, '') !== projectRoot) {
createNextConfigFile(options, context);
copySync(join(projectRoot, 'public'), join(options.outputPath, 'public'), {
dereference: true,
});
}
return { success: true };
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export function createNextConfigFile(
options: NextBuildBuilderOptions,
context: ExecutorContext
) {
// Don't overwrite the next.config.js file if output path is the same as the source path.
if (
options.outputPath.replace(/\/$/, '') ===
context.projectGraph.nodes[context.projectName].data.root
) {
return;
}
const projectRoot = context.projectGraph.nodes[context.projectName].data.root;
const configRelativeToProjectRoot = findNextConfigPath(
projectRoot,
Expand Down