Unverified Commit d459b5f9 authored by Axel Mohamed SADAT's avatar Axel Mohamed SADAT Committed by GitHub

fix(NODE_ENV): Warn when launching start or build on development (#14033)

The PR aims to fix [#14022](https://github.com/vercel/next.js/issues/14022)
Co-authored-by: 's avatarTim Neutkens <6324199+timneutkens@users.noreply.github.com>
parent 21f8c6a7
...@@ -88,8 +88,18 @@ const defaultEnv = command === 'dev' ? 'development' : 'production' ...@@ -88,8 +88,18 @@ const defaultEnv = command === 'dev' ? 'development' : 'production'
const standardEnv = ['production', 'development', 'test'] const standardEnv = ['production', 'development', 'test']
if (process.env.NODE_ENV && !standardEnv.includes(process.env.NODE_ENV)) { if (process.env.NODE_ENV) {
log.warn(NON_STANDARD_NODE_ENV) const isNotStandard = !standardEnv.includes(process.env.NODE_ENV)
const shouldWarnCommands =
process.env.NODE_ENV === 'development'
? ['start', 'build']
: process.env.NODE_ENV === 'production'
? ['dev']
: []
if (isNotStandard || shouldWarnCommands.includes(command)) {
log.warn(NON_STANDARD_NODE_ENV)
}
} }
;(process.env as any).NODE_ENV = process.env.NODE_ENV || defaultEnv ;(process.env as any).NODE_ENV = process.env.NODE_ENV || defaultEnv
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
waitFor, waitFor,
initNextServerScript, initNextServerScript,
nextBuild, nextBuild,
nextStart,
} from 'next-test-utils' } from 'next-test-utils'
const appDir = join(__dirname, '..') const appDir = join(__dirname, '..')
...@@ -135,4 +136,47 @@ describe('Non-Standard NODE_ENV', () => { ...@@ -135,4 +136,47 @@ describe('Non-Standard NODE_ENV', () => {
await killApp(app) await killApp(app)
expect(output).toContain(warningText) expect(output).toContain(warningText)
}) })
it('should show the warning with NODE_ENV set to production with next dev', async () => {
let output = ''
app = await launchApp(appDir, await findPort(), {
env: {
NODE_ENV: 'production',
},
onStderr(msg) {
output += msg || ''
},
})
await waitFor(2000)
await killApp(app)
expect(output).toContain(warningText)
})
it('should show the warning with NODE_ENV set to development with next build', async () => {
const { stderr } = await nextBuild(appDir, [], {
env: {
NODE_ENV: 'development',
},
stderr: true,
})
expect(stderr).toContain(warningText)
})
it('should show the warning with NODE_ENV set to development with next start', async () => {
let output = ''
await nextBuild(appDir)
app = await nextStart(appDir, await findPort(), {
env: {
NODE_ENV: 'development',
},
onStderr(msg) {
output += msg || ''
},
})
await waitFor(2000)
await killApp(app)
expect(output).toContain(warningText)
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment