From e363e7371575e75fcb4e697f55effaf775bec860 Mon Sep 17 00:00:00 2001 From: Arana Jhonny Date: Thu, 5 Jan 2017 17:00:55 -0400 Subject: [PATCH] Fix Improve "pages/ not found error" (#624) * fix not found error * add comment --- bin/next-build | 20 +++++++++++++++++++- bin/next-dev | 21 ++++++++++++++------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/bin/next-build b/bin/next-build index 4e11988906..e52d0ce35e 100755 --- a/bin/next-build +++ b/bin/next-build @@ -1,6 +1,7 @@ #!/usr/bin/env node -import { resolve } from 'path' +import { resolve, join } from 'path' +import { exists } from 'mz/fs' import parseArgs from 'minimist' import build from '../server/build' @@ -27,6 +28,23 @@ if (argv.help) { const dir = resolve(argv._[0] || '.') +// Check if pages dir exists and warn if not +exists(dir) +.then(async () => { + if (!(await exists(join(dir, 'pages')))) { + if (await exists(join(dir, '..', 'pages'))) { + console.error('> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?') + } else { + console.error('> Couldn\'t find a `pages` directory. Please create one under the project root') + } + process.exit(1) + } +}) +.catch((err) => { + console.error(err) + process.exit(1) +}) + build(dir) .catch((err) => { console.error(err) diff --git a/bin/next-dev b/bin/next-dev index 748307c70f..4c86f50206 100755 --- a/bin/next-dev +++ b/bin/next-dev @@ -37,14 +37,9 @@ if (argv.help) { const dir = resolve(argv._[0] || '.') -const srv = new Server({ dir, dev: true }) -srv.start(argv.port) +// Check if pages dir exists and warn if not +exists(dir) .then(async () => { - if (!process.env.NOW) { - console.log(`> Ready on http://localhost:${argv.port}`) - } - - // Check if pages dir exists and warn if not if (!(await exists(join(dir, 'pages')))) { if (await exists(join(dir, '..', 'pages'))) { console.error('> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?') @@ -58,3 +53,15 @@ srv.start(argv.port) console.error(err) process.exit(1) }) + +const srv = new Server({ dir, dev: true }) +srv.start(argv.port) +.then(async () => { + if (!process.env.NOW) { + console.log(`> Ready on http://localhost:${argv.port}`) + } +}) +.catch((err) => { + console.error(err) + process.exit(1) +}) -- GitLab