From e763a6084046580484e7b5793703d703b6b50e95 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Fri, 14 Sep 2018 22:44:17 +0200 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20read=20package.scripts=20if=20t?= =?UTF-8?q?here=E2=80=99s=20no=20scripts=20defined=20(#5168)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/next-dev | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/next-dev b/bin/next-dev index 2a3c8f6c..89227ae5 100755 --- a/bin/next-dev +++ b/bin/next-dev @@ -1,7 +1,7 @@ #!/usr/bin/env node import { resolve, join } from 'path' import parseArgs from 'minimist' -import { existsSync, readFileSync } from 'fs' +import { existsSync } from 'fs' import Server from '../server' import { printAndExit } from '../lib/utils' @@ -65,9 +65,14 @@ srv.start(argv.port, argv.hostname) const pkgAppPath = require('find-up').sync('package.json', { cwd: dir }) - const appPackage = JSON.parse(readFileSync(pkgAppPath, 'utf8')) - const nextScript = Object.entries(appPackage.scripts).find(scriptLine => scriptLine[1] === 'next') - if (nextScript) errorMessage += `\nUse \`npm run ${nextScript[0]} -- -p \`.` + const appPackage = require(pkgAppPath) + if (appPackage.scripts) { + const nextScript = Object.entries(appPackage.scripts).find(scriptLine => scriptLine[1] === 'next') + if (nextScript) { + errorMessage += `\nUse \`npm run ${nextScript[0]} -- -p \`.` + } + } + console.error(errorMessage) } else { console.error(err)