未验证 提交 261eb163 编写于 作者: T Tim Neutkens 提交者: GitHub

Only check if BUILD_ID exists when reading throws error (#5834)

We don't have to check if the file already exists here, since it's always in production mode (dev overrides the readBuildId method to always be `development`) If the file is not found (error is thrown) we check if the file exists. If not we throw a helpful error. In other cases we throw the original error.
上级 510eb577
......@@ -253,9 +253,15 @@ export default class Server {
}
readBuildId () {
if (!fs.existsSync(resolve(this.distDir, BUILD_ID_FILE))) {
throw new Error(`Could not find a valid build in the '${this.distDir}' directory! Try building your app with 'next build' before starting the server.`)
const buildIdFile = join(this.distDir, BUILD_ID_FILE)
try {
return fs.readFileSync(buildIdFile, 'utf8').trim()
} catch (err) {
if (!fs.existsSync(buildIdFile)) {
throw new Error(`Could not find a valid build in the '${this.distDir}' directory! Try building your app with 'next build' before starting the server.`)
}
throw err
}
return fs.readFileSync(join(this.distDir, BUILD_ID_FILE), 'utf8').trim()
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册