Unverified Commit 690208b1 authored by Steven's avatar Steven Committed by GitHub

fix: show error when "next start" is used with "output" config (#47989)

fix #47334
fix NEXT-861
parent 1e81af04
...@@ -82,7 +82,7 @@ Or using the `PORT` environment variable: ...@@ -82,7 +82,7 @@ Or using the `PORT` environment variable:
PORT=4000 npx next dev PORT=4000 npx next dev
``` ```
> Note: `PORT` can not be set in `.env` as booting up the HTTP server happens before any other code is initialized. > Note: `PORT` cannot be set in `.env` as booting up the HTTP server happens before any other code is initialized.
You can also set the hostname to be different from the default of `0.0.0.0`, this can be useful for making the application available for other devices on the network. The default hostname can be changed with `-H`, like so: You can also set the hostname to be different from the default of `0.0.0.0`, this can be useful for making the application available for other devices on the network. The default hostname can be changed with `-H`, like so:
...@@ -106,7 +106,9 @@ Or using the `PORT` environment variable: ...@@ -106,7 +106,9 @@ Or using the `PORT` environment variable:
PORT=4000 npx next start PORT=4000 npx next start
``` ```
> Note: `PORT` can not be set in `.env` as booting up the HTTP server happens before any other code is initialized. > Note: `PORT` cannot be set in `.env` as booting up the HTTP server happens before any other code is initialized.
> Note: `next start` cannot be used with `output: 'standalone'` or `output: 'export'`.
### Keep Alive Timeout ### Keep Alive Timeout
......
...@@ -164,6 +164,17 @@ export class NextServer { ...@@ -164,6 +164,17 @@ export class NextServer {
private async getServer() { private async getServer() {
if (!this.serverPromise) { if (!this.serverPromise) {
this.serverPromise = this.loadConfig().then(async (conf) => { this.serverPromise = this.loadConfig().then(async (conf) => {
if (!this.options.dev) {
if (conf.output === 'standalone') {
log.warn(
`"next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.`
)
} else if (conf.output === 'export') {
throw new Error(
`"next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.`
)
}
}
if (conf.experimental.appDir) { if (conf.experimental.appDir) {
process.env.NEXT_PREBUNDLED_REACT = '1' process.env.NEXT_PREBUNDLED_REACT = '1'
overrideBuiltInReactPackages() overrideBuiltInReactPackages()
......
...@@ -201,7 +201,7 @@ async function runTests({ ...@@ -201,7 +201,7 @@ async function runTests({
} }
} }
describe('app dir with output export', () => { describe('app dir with output export (next dev / next build)', () => {
it.each([ it.each([
{ isDev: true, trailingSlash: false }, { isDev: true, trailingSlash: false },
{ isDev: true, trailingSlash: true }, { isDev: true, trailingSlash: true },
......
/* eslint-env jest */
import { join } from 'path'
import fs from 'fs-extra'
import {
check,
File,
findPort,
killApp,
nextBuild,
nextStart,
} from 'next-test-utils'
const appDir = join(__dirname, '..')
const distDir = join(appDir, '.next')
const exportDir = join(appDir, 'out')
const nextConfig = new File(join(appDir, 'next.config.js'))
let app
describe('app dir with output export (next start)', () => {
afterEach(async () => {
await killApp(app)
nextConfig.restore()
await fs.remove(distDir)
await fs.remove(exportDir)
})
it('should error during next start with output export', async () => {
const { code } = await nextBuild(appDir)
expect(code).toBe(0)
const port = await findPort()
let stderr = ''
app = await nextStart(appDir, port, {
onStderr(msg: string) {
stderr += msg || ''
},
})
await check(() => stderr, /error/i)
expect(stderr).toContain(
'"next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.'
)
})
it('should warn during next start with output standalone', async () => {
nextConfig.replace(`output: 'export'`, `output: 'standalone'`)
const { code } = await nextBuild(appDir)
expect(code).toBe(0)
const port = await findPort()
let stderr = ''
app = await nextStart(appDir, port, {
onStderr(msg: string) {
stderr += msg || ''
},
})
await check(() => stderr, /warn/i)
expect(stderr).toContain(
`warn - "next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.`
)
})
})
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