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): set NX_NEXT_DIR when running next server #17205

Merged
merged 1 commit into from
May 25, 2023
Merged
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
26 changes: 14 additions & 12 deletions packages/next/src/executors/server/server.impl.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'dotenv/config';
import * as net from 'net';
import {
ExecutorContext,
logger,
parseTargetString,
readTargetOptions,
} from '@nx/devkit';
import { resolve } from 'path';
import { join, resolve } from 'path';

import {
NextBuildBuilderOptions,
Expand All @@ -25,15 +23,6 @@ export default async function* serveExecutor(
if (options.customServerTarget) {
return yield* customServer(options, context);
}
// Cast to any to overwrite NODE_ENV
(process.env as any).NODE_ENV = process.env.NODE_ENV
? process.env.NODE_ENV
: options.dev
? 'development'
: 'production';

// Setting port that the custom server should use.
(process.env as any).PORT = options.port;

const buildOptions = readTargetOptions<NextBuildBuilderOptions>(
parseTargetString(options.buildTarget, context.projectGraph),
Expand All @@ -43,6 +32,19 @@ export default async function* serveExecutor(

const { port, keepAliveTimeout, hostname } = options;

// This is required for the default custom server to work. See the @nx/next:app generator.
process.env.NX_NEXT_DIR = root;

// Cast to any to overwrite NODE_ENV
(process.env as any).NODE_ENV = process.env.NODE_ENV
? process.env.NODE_ENV
: options.dev
? 'development'
: 'production';

// Setting port that the custom server should use.
process.env.PORT = `${options.port}`;

const args = createCliOptions({ port, keepAliveTimeout, hostname });

const nextDir = resolve(context.root, buildOptions.outputPath);
Expand Down