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(NODE_ENV): Warn when launching start or build on development #14033

Merged
merged 8 commits into from Dec 7, 2021
14 changes: 12 additions & 2 deletions packages/next/bin/next.ts
Expand Up @@ -88,8 +88,18 @@ const defaultEnv = command === 'dev' ? 'development' : 'production'

const standardEnv = ['production', 'development', 'test']

if (process.env.NODE_ENV && !standardEnv.includes(process.env.NODE_ENV)) {
log.warn(NON_STANDARD_NODE_ENV)
if (process.env.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
Expand Down
Expand Up @@ -9,6 +9,7 @@ import {
waitFor,
initNextServerScript,
nextBuild,
nextStart,
} from 'next-test-utils'

const appDir = join(__dirname, '..')
Expand Down Expand Up @@ -135,4 +136,47 @@ describe('Non-Standard NODE_ENV', () => {
await killApp(app)
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)
})
})