【问题标题】:Error: getaddrinfo ENOTFOUND undefined on a specific page错误:getaddrinfo ENOTFOUND 在特定页面上未定义
【发布时间】:2022-12-22 06:20:00
【问题描述】:

我们使用 next.js 和 knex.js 作为查询生成器,在所有页面中一切正常,除了在我们有 ISR aka getStaticPaths 的页面中,并且在该方法中,每当我们尝试执行查询时,我们都会收到以下错误,但在其他没有getStaticPaths的页面一切正常:

Server Error
Error: getaddrinfo ENOTFOUND undefined

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
GetAddrInfoReqWrap.onlookup [as oncomplete]
node:dns (71:26)

其他任何地方都没有提供更多信息。正如错误消息中所示,数据库主机未定义,但为什么除了getStaticPaths之外,它在任何地方都可以正确读取??

【问题讨论】:

    标签: next.js knex.js


    【解决方案1】:

    原来我们在next.config.js 中启用了这个实验性功能,当它打开时,.env 变量都是未定义的,并且没有在getStaticPaths 中正确加载但是一旦调用getStaticProps 一切正常,我不知道原因,但关闭 workerThreads 解决了问题:

    experimental: {
        workerThreads: false //fixed the problem
    },
    

    【讨论】:

      猜你喜欢
      • 2017-10-16
      • 2018-03-03
      • 2020-10-19
      • 2014-10-20
      • 2018-05-24
      • 2016-04-20
      • 2018-01-31
      • 2021-07-18
      • 1970-01-01
      相关资源
      最近更新 更多