Commit 4eb86dc5 authored by Xuezheng Ma's avatar Xuezheng Ma Committed by Tim Neutkens

Added proper error for running `next start` on dev build (#2337)

* Added proper error for running `next start` on dev build

* Check if build exist before usage

* Move BUILD_ID check from bin/next-start to server/index.js

* Check env before checking build
parent b2b7946c
......@@ -3,8 +3,6 @@
import { resolve } from 'path'
import parseArgs from 'minimist'
import Server from '../server'
import { existsSync } from 'fs'
import getConfig from '../server/config'
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
......@@ -47,15 +45,8 @@ if (argv.help) {
}
const dir = resolve(argv._[0] || '.')
const dist = getConfig(dir).distDir
const srv = new Server({ dir })
if (!existsSync(resolve(dir, dist, 'BUILD_ID'))) {
console.error(`> Could not find a valid build in the '${dist}' directory! Try building your app with 'next build' before starting the server.`)
process.exit(1)
}
srv.start(argv.port, argv.hostname)
.then(() => {
if (!process.env.NOW) {
......
......@@ -34,6 +34,10 @@ export default class Server {
this.http = null
this.config = getConfig(this.dir, conf)
this.dist = this.config.distDir
if (!dev && !fs.existsSync(resolve(dir, this.dist, 'BUILD_ID'))) {
console.error(`> Could not find a valid build in the '${this.dist}' directory! Try building your app with 'next build' before starting the server.`)
process.exit(1)
}
this.buildStats = !dev ? require(join(this.dir, this.dist, 'build-stats.json')) : null
this.buildId = !dev ? this.readBuildId() : '-'
this.renderOpts = {
......
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