我在 Vercel 部署期间遇到此错误:
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11457:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
cause: Error: connect ECONNREFUSED 127.0.0.1:3000
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3000
}
}
Error occurred prerendering page "/match". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11457:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Run Code Online (Sandbox Code Playgroud)
我想可能是因为http://localhost:3000/api/event,我怎样才能替换正确的网址localhost?
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11457:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
cause: Error: connect ECONNREFUSED 127.0.0.1:3000
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3000
}
}
Error occurred prerendering page "/match". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11457:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Run Code Online (Sandbox Code Playgroud)
如果您尝试在构建时从服务器组件调用内部 API 路由,而此时没有应用程序正在运行(应用程序正在构建但尚未部署),则会出现此错误。Next.js 的 Tim Neutkens在 GitHub 问题上指出了类似的错误:
这是因为您尝试在构建期间从内部 api 路由获取,这是不受支持的。
无需从服务器组件调用内部 API 路由,然后服务器组件调用您的 DB 或 CMS,而是直接从组件访问它们。它有助于避免错误以及额外的无用 API 调用。
已经说过了,如果 API 不是您内部的,您可以替换
fetch('http://localhost:3000/api/event')
Run Code Online (Sandbox Code Playgroud)
和
fetch(process.env.URL + '/api/even')
Run Code Online (Sandbox Code Playgroud)
并创建一个.env文件,在其中添加:
URL=http://localhost:3000
Run Code Online (Sandbox Code Playgroud)
然后在 Vercel 仪表板上,使用URL生产 URL 设置环境变量。
| 归档时间: |
|
| 查看次数: |
6417 次 |
| 最近记录: |