Skip to content

Commit e363e73

Browse files
aranajhonnyrauchg
authored andcommitted
Fix Improve "pages/ not found error" (vercel#624)
* fix not found error * add comment
1 parent b8373b8 commit e363e73

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

bin/next-build

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22

3-
import { resolve } from 'path'
3+
import { resolve, join } from 'path'
4+
import { exists } from 'mz/fs'
45
import parseArgs from 'minimist'
56
import build from '../server/build'
67

@@ -27,6 +28,23 @@ if (argv.help) {
2728

2829
const dir = resolve(argv._[0] || '.')
2930

31+
// Check if pages dir exists and warn if not
32+
exists(dir)
33+
.then(async () => {
34+
if (!(await exists(join(dir, 'pages')))) {
35+
if (await exists(join(dir, '..', 'pages'))) {
36+
console.error('> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?')
37+
} else {
38+
console.error('> Couldn\'t find a `pages` directory. Please create one under the project root')
39+
}
40+
process.exit(1)
41+
}
42+
})
43+
.catch((err) => {
44+
console.error(err)
45+
process.exit(1)
46+
})
47+
3048
build(dir)
3149
.catch((err) => {
3250
console.error(err)

bin/next-dev

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,9 @@ if (argv.help) {
3737

3838
const dir = resolve(argv._[0] || '.')
3939

40-
const srv = new Server({ dir, dev: true })
41-
srv.start(argv.port)
40+
// Check if pages dir exists and warn if not
41+
exists(dir)
4242
.then(async () => {
43-
if (!process.env.NOW) {
44-
console.log(`> Ready on http://localhost:${argv.port}`)
45-
}
46-
47-
// Check if pages dir exists and warn if not
4843
if (!(await exists(join(dir, 'pages')))) {
4944
if (await exists(join(dir, '..', 'pages'))) {
5045
console.error('> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?')
@@ -58,3 +53,15 @@ srv.start(argv.port)
5853
console.error(err)
5954
process.exit(1)
6055
})
56+
57+
const srv = new Server({ dir, dev: true })
58+
srv.start(argv.port)
59+
.then(async () => {
60+
if (!process.env.NOW) {
61+
console.log(`> Ready on http://localhost:${argv.port}`)
62+
}
63+
})
64+
.catch((err) => {
65+
console.error(err)
66+
process.exit(1)
67+
})

0 commit comments

Comments
 (0)