Skip to content

Commit e763a60

Browse files
authoredSep 14, 2018
Don’t read package.scripts if there’s no scripts defined (#5168)
1 parent 34cb05a commit e763a60

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed
 

‎bin/next-dev

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import { resolve, join } from 'path'
33
import parseArgs from 'minimist'
4-
import { existsSync, readFileSync } from 'fs'
4+
import { existsSync } from 'fs'
55
import Server from '../server'
66
import { printAndExit } from '../lib/utils'
77

@@ -65,9 +65,14 @@ srv.start(argv.port, argv.hostname)
6565
const pkgAppPath = require('find-up').sync('package.json', {
6666
cwd: dir
6767
})
68-
const appPackage = JSON.parse(readFileSync(pkgAppPath, 'utf8'))
69-
const nextScript = Object.entries(appPackage.scripts).find(scriptLine => scriptLine[1] === 'next')
70-
if (nextScript) errorMessage += `\nUse \`npm run ${nextScript[0]} -- -p <some other port>\`.`
68+
const appPackage = require(pkgAppPath)
69+
if (appPackage.scripts) {
70+
const nextScript = Object.entries(appPackage.scripts).find(scriptLine => scriptLine[1] === 'next')
71+
if (nextScript) {
72+
errorMessage += `\nUse \`npm run ${nextScript[0]} -- -p <some other port>\`.`
73+
}
74+
}
75+
7176
console.error(errorMessage)
7277
} else {
7378
console.error(err)

0 commit comments

Comments
 (0)
Please sign in to comment.