1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

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
This commit is contained in:
Xuezheng Ma 2017-06-26 15:18:56 -05:00 committed by Tim Neutkens
parent b2b7946c53
commit 4eb86dc5f8
2 changed files with 4 additions and 9 deletions

View file

@ -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) {

View file

@ -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 = {