Since Next.js 13, I noticed that some of my projects failed to deploy when reading environment variable that contains Hygraph Public API, specifically “Hygraph High Performance Public API”.
I attached one example from a project currently using Next.js 14. I have altered the error log where it shows the real API endpoint and replace it with XXXXX
Strangely, the Hygraph Authentication Token works well without problem, even though I put it in the same environment file as Hygraph Public API
The quick fix/workaround with this problem is to use the hard-coded API endpoint I mentioned above (the one stored in javascript variable). I intended to not expose the Hygraph Public API in the codebase/source code, but since it keeps throwing errors, I have to use this workaround
TypeError: Failed to parse URL from "https://ap-southeast-2.cdn.hygraph.com/content/xxxxx/master"
at new Request (node:internal/deps/undici/undici:5272:19)
at i (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:177224)
... 5 lines matching cause stack trace ...
at stringify (<anonymous>)
at eR (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:134889)
at eP (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135332) {
[cause]: TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:405:5)
at new URL (node:internal/url:676:13)
at new Request (node:internal/deps/undici/undici:5270:25)
at i (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:177224)
at v (/vercel/path0/.next/server/app/page.js:14:116)
at N (/vercel/path0/.next/server/app/page.js:62:131)
at em (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:131226)
at /vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142926
at Array.toJSON (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:146504)
at stringify (<anonymous>) {
input: '"https://ap-southeast-2.cdn.hygraph.com/content/xxxxx/master"',
code: 'ERR_INVALID_URL'
}
}