Next.js Discord

Discord Forum

Tutorial on Next.js site (How to Load Data from a File in Next.js) doesn't work...

Unanswered
Brown bear posted this in #help-forum
Open in Discord
Avatar
Brown bearOP
So I'm trying to follow the tutorial on the NextJS site: https://vercel.com/guides/loading-static-file-nextjs-api-route

Basically, it doesn't seem to match up correctly to the files created when I run create-next-app - I don't even have the pages folder mentioned! How do I need to adapt this tutorial to make it work with the current version of Next.js? Thanks in advance!

4 Replies

Avatar
ncls.
Next.js basically has two versions. In one you have the pages folder, in the other you have the app folder. create-next-app will ask you which one you'd like to use ("Would you like to use App Router?").
Check if you have the app folder.
Avatar
Brown bearOP
oh wow, now I feel stupid :lolsob: thank you!
Avatar
Brown bearOP
So I had another crack at this with a new project based off the pages router... and I still don't seem to be able to get this working! Everything is in place, but I get the following error:
 Unhandled Runtime Error
TypeError: Cannot read properties of undefined (reading 'name')


I've gone as far as to clone the tutorial repo, which worked fine... but then when I copied the edited files into my own project (after installing swr) I still get the same error message! Is there anything else I might be missing? It seems like it can't find the json file maybe, but it's definitely there!
Avatar
ncls.
Share some code