Nextjs
Published in

Nextjs

Nextjs

Is the next.js pages folder required?

The src folder is an alternative to the next.js pages folder.

In the nextjs pages, the pagesfolder is required that is true. But if you have an old reactjs-based project, you convert it into the nextjs.

Demo Code

I know the src folder is very common in reactjs development.

Then you have an option for the src folder for your project. You should move all router files into src/pages folder.

But if you add all routes files, move to the src folder. Then nextjs generate an error.

Error: > Couldn’t find a `pages` directory.
Error: > Couldn’t find a `pages` directory.

Important Point

  1. If you add routing in src . Then you face a couldn’t find a pages directory Error.
  2. You have a pages folder in your directory. Then nextjs will ignore src/pages folder.
  3. In src/pagesfolder environment variables are not working.

Conclusion

You use an src folder as the main code folder in your old day. When I shift react to next, I miss a lot of time in the src folder.

but when you use the src/pages folder in your project. Then you never use environment variables in your project.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rajdeep singh

Rajdeep singh

526 Followers

JavaScript || Reactjs || Nextjs || Python || Rust || Biotechnology || Bioinformatic || Front-end Developer || Writer || https://officialrajdeepsingh.dev/