简体   繁体   English

如何在 Next.js 中以编程方式停止构建

[英]How to stop build programatically in Next.js

Is there a way to stop npm run build programatically in Next.js as soon as a certain Error occurs in getStaticProps ?一旦在getStaticProps中发生某个错误,是否有办法在 Next.js 中以编程方式停止npm run build Just throwing an Error does not stop the build process.只是抛出一个错误并不会停止构建过程。

I've been trying to achieve the same thing but apparently there is no official way.我一直在努力实现同样的目标,但显然没有官方途径。 What I've tried is the following code inside next.config.js :我试过的是next.config.js中的以下代码:

module.exports = async (phase, { defaultConfig }) => {
  try {
    console.log("fetching app info", phase)
    const appInfo = await fetchAppInfo()
    fs.writeJson("./src/appInfo.json", appInfo)
  } catch (e) {
    console.log(e)
    throw e
  }

  return yourConfig
}

If you don't return the expected config for next js, the build procedure will be cancled如果您没有为下一个 js 返回预期的配置,构建过程将被取消

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM