From 4eb86dc5f8cf0aaab6984956deed40a440ebfd11 Mon Sep 17 00:00:00 2001 From: Xuezheng Ma Date: Mon, 26 Jun 2017 15:18:56 -0500 Subject: [PATCH] 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 --- bin/next-start | 9 --------- server/index.js | 4 ++++ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/bin/next-start b/bin/next-start index 09d22231..bfd78567 100755 --- a/bin/next-start +++ b/bin/next-start @@ -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) { diff --git a/server/index.js b/server/index.js index 488d850a..9a8f7ce5 100644 --- a/server/index.js +++ b/server/index.js @@ -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 = {