nextjs 部署失败:cause: Error: unable to verify the first certificate
description
写好了nextjs代码 推送到github,vercel自动部署nextjs项目过程一直报错。
之前不报错的,现在报错,很是奇怪。
error log
TypeError: fetch failedat node:internal/deps/undici/undici:12625:11at process.processTicksAndRejections (node:internal/process/task_queues:95:5)at async Object.p [as generateStaticParams] (/vercel/path0/.next/server/app/posts/[postid]/page.js:1:151665)at async buildParams (/vercel/path0/node_modules/next/dist/build/utils.js:1026:40)at async /vercel/path0/node_modules/next/dist/build/utils.js:1043:33at async /vercel/path0/node_modules/next/dist/build/utils.js:1178:114at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:154:20) {cause: Error: unable to verify the first certificateat TLSSocket.onConnectSecure (node:_tls_wrap:1659:34)at TLSSocket.emit (node:events:517:28)at TLSSocket._finishInit (node:_tls_wrap:1070:8)at ssl.onhandshakedone (node:_tls_wrap:856:12)at TLSWrap.callbackTrampoline (node:internal/async_hooks:128:17) {code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'}
}
困扰了我几个月,今天算是解决了。
原因是在server 代码代码里面调用自身的api接口,api接口的hostname 包含https。
实际上这个逻辑就有问题,自己调用自己的api接口不合理。
解决办法
最后把调用api的代码删了,换成action,直接写业务代码就好了,api接口里面也替换成action,实现了代码复用。
总结
server: 不要自己调用自己的api,直接换成业务代码;
client:不需要写hostname,直接fetch(‘/api/path’)