Vercel / NextJS Error Prerendering index. "Only absolute URLs are supported"

Hi there.

When trying to deploy my DatoCMS project on Vercel, I keep getting an error that it wonā€™t accept absolute links. In my dev environment, there are zero errors after running npm run-script build.

Hereā€™s my repo: GitHub - kr1st1nagr03g3r/honey-shark .

Any ideas why this isnā€™t working? Iā€™ve scrubbed my entire build for absolute linksā€¦ My components and every page.

  • Iā€™ve followed the links in the errors as well with no luck. Thanks!
  • Iā€™ve tried deleting node_modules and package-lock.json and reinstalled npm. No luck.

1 Like

I ended up figuring this out, but perhaps leave this post here for anyone who might struggle. I am new to linking a CMS to my Next.js project, so maybe a newbie can get help from this info.

It is super frustrating to figure this out as for security reasons, .env files are usually in the gitignore and you never see the example of them anywhere - because theyā€™re secret.

Your .env file must be in the root of your project. New file > name it .env > put in the following information (xxx means your API token) and look like this:

DATOCMS_API_READONLY_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxx
(from your Dato dashboard > settings > APIs > read-only token

API_URL=https://graphql.datocms.com
(From the same dashboard, under ā€œpermissionsā€)

NEXT_EXAMPLE_CMS_DATOCMS_PREVIEW_SECRET=xxxxxxxx
(Iā€™m not sure if you need this - but here it is)

Within your Vercel project settings: ensure you also have the same API key and url (I didnā€™t use the secret and it worked): Environment Variables ā€“ Vercel Docs

I have deployed successfully.

1 Like

Thank you for sharing the solution @kristinagroeger!
Iā€™ll leave it here as it can certainly be a resource for anyone running into the same issue, as you said.

Thank you once again!

1 Like