fix(nextjs): NODE_ENV defaults to production for builds (#5574)

This commit is contained in:
Kirils L 2021-05-07 17:55:16 +01:00 committed by GitHub
parent c0d79baad5
commit da27b2bd6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -354,14 +354,22 @@ describe('Next.js Applications', () => {
future: {
// Nx doesn't support webpack 5 yet
webpack5: false,
},
webpack: (c) => {
console.log('NODE_ENV is', process.env.NODE_ENV);
return c;
}
}
`
);
runCLI(`build ${appName}`);
// deleting `NODE_ENV` value, so that it's `undefined`, and not `"test"`
// by the time it reaches the build executor.
// this simulates existing behaviour of running a next.js build executor via Nx
delete process.env.NODE_ENV;
const result = runCLI(`build ${appName}`);
checkFilesExist(`dist/apps/${appName}/next.config.js`);
expect(result).toContain('NODE_ENV is production');
}, 120000);
it('should support --js flag', async () => {

View File

@ -23,6 +23,8 @@ export default async function buildExecutor(
options: NextBuildBuilderOptions,
context: ExecutorContext
) {
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
const root = resolve(context.root, options.root);
const projGraph = createProjectGraph();