"A Blog example using Next.js and DatoCMS" doesn't run locally

I have followed the steps on this tutorial, including the ā€œDeploy with DatoCMSā€ button: A Blog example using Next.js and DatoCMS

My GitHub repo was created, and it connected and deployed to Vercel successfully, and I can view the sample blog running on the provided Vercel URL. It looks great.

But after I cloned the repo down to my local, and ran npm install and npm run dev, I was unable to view the blog at localhost:3000. At first I received an error suggesting that the next.js version was old, so I ran npm install next@latest which took care of that error.

But now when I run the app I receive this error:

Error: Invalid revalidate value ā€œnullā€ on ā€œ/ā€, must be a non-negative number or false

The error points to line 26 in the file lib/datocms.js, which is a fetch call to the Datocms graphql endpoint.

Since I have followed the demo steps exactly and havenā€™t modified anything else, Iā€™m not sure where to go from here. Is this demo still valid or am I wasting my time? Iā€™d love to get this working as the workflow seems pretty promising.

Thanks.

Hey @garyesmith,

Hmm, it seems to work for me here (on the default Next version). Did you remember to set the env vars by making an .env.local file, copied from .env.local.example, and set your API keys there?

If that wasnā€™t the issue, could you please provide a screen recording or some screenshots with whatever errors you see?

The Next.js version warning is normal, since that particular blog demo is still on Next 13. I wouldnā€™t recommend force-upgrading that to v14 or 15 yet (you can try it, I just donā€™t know if it works, since not every Next upgrade is automatically backward-compatible without changes).

We do have some starters on Next 14:

We donā€™t have a Next 15 one yet. Even though Vercel released it to production, it still uses a pre-release version of React 19 and that causes issues with several dependencies (both ours and third-party) because itā€™s a release candidate and that messes with SemVer in package.json. Some customers have tried it with mixed success, but I wouldnā€™t recommend it yet. Next 14 should work fine and offers most of the same features.

Hi Roger,

Thanks for your quick reply. Your suggestions led me in the right direction but there are a couple things in the example docs that seem to be incomplete or not quite accurate, so Iā€™ll describe them for you below.

First, I reverted Next.js back to 13.4.7 as it was originally in the demo repo. I have no personal preference regarding the version.

Then I noticed that the demo README had instructed me to create a file called .env, not .env.local as you suggested. So I renamed it.

Also in the demo README it says to obtain the token from under Read-only API token in the settings for the project inside Datocms. But this token did not work, perhaps because all the Permission toggles for that token were disabled (greyed out) in the interface and could not be enabled.

But I noticed a setting for GraphQL API Token which has the Permissions toggles enabled. So I tried copying that token into my .env.local instead, and then I was able to npm run dev and view the site at localhost:3000.

I also had to go into Vercel and change the NEXT_DATOCMS_API_TOKEN environment variable to that same GraphQL API Token before I was able to redeploy the app on Vercel successfully.

Iā€™m not sure if these discrepancies happened because the Datocms interface has changed since the demo docs were created in 2023, or if I have done something in an unconventional way, but it seems I can now move forward.

Thanks again.

Glad you got it working! Welcome to Dato, and please feel free to ask anytime something comes up :slight_smile: Hope you like our service.

And sorry about the errorsā€¦ that is an older demo, and things have changed since it was first released. We shouldā€™ve been better about keeping the readme updated.

Fixed!

Thatā€™s odd; it should work. I just tried on mine. Is it possible a char was missed or an extra whitespace was added? I wouldnā€™t worry about it too much if you already got another key working, but if Iā€™d be happy to keep troubleshooting it with you if itā€™s an issue.

The permissions were all greyed out for that key because thatā€™s one of the default keys (alongside the full access one). You can regenerate it but you cannot modify its permissions. You can always create new roles & keys as needed, though, like with the example GraphQL-only one.

Thatā€™s really weird. I just tried again, starting from the ā€œDeploy DatoCMS Starterā€ button, then choosing Vercel, then letting it create a repo, then added the DatoCMS integration (still in Vercelā€™s setup). Then it built and deployed the site: https://nextjsblogtest-ebon.vercel.app/ I did not have to manually look at, copy, or change any API keys at all.

Again, Iā€™m not sure what happened thereā€¦ we can look into it more if youā€™d like, but if it was just a fluke, I wouldnā€™t worry about it too much. Itā€™s not something we have heard other reports of (so far).

Thank you for looking further into this, I appreciate it. Things are working for me now and I am moving forward, so I donā€™t think thereā€™s any need to investigate further. Perhaps I did something unusual or have a different setup somewhere, Iā€™m not sure, but since the GraphQL token is working for me Iā€™m happy to keep it.

1 Like