Next vs Gatsby
Saturday, May 8, 2021
Searching online you can find plenty of content comparing NextJS vs Gatsby. Which one should I use for which type of project? The real answer, like most times in development, is "it depends".
I think that the general opinion up to this point shakes out sort of like if you are want to build a site that's not going to change often, or just at the time of writing a post (like a blog perhaps?) Gatsby is a great choice. If you want the power of server side rendering your dynamic content, or a large inventory online store you'd likely to be better served for reaching towards NextJS.
These days NextJS can cover both static and server generated pretty well, and has a newer feature, incremental static regeneration, allowing statically generated content which updates with dynamic updates. It feels like Gatsby can do a bunch with the plugin ecosystem, but without a plugin you might be slightly constrained. NextJS doesn't have as much of the drop in place and be product functionality but has the flexibility of working more directly on the server or client as needed.
As an exercise I migrated this blog from Gatsby to NextJS to see how tricky that transition would be. There we a few bumps along the way but nowhere near as many as you'd expect. Mostly simple things like moving assets from static to public, but I did have a bit of a struggle trying to get the next system to deploy to Netlify properly.
10:00:00 AM: Error: > Build failed because of webpack errors
10:00:00 AM: at /opt/build/repo/node_modules/next/dist/build/index.js:17:924
10:00:00 AM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:6:584)
10:00:00 AM: error Command failed with exit code 1.
10:00:00 AM: info Visit <https://yarnpkg.com/en/docs/cli/run> for documentation about this command.
I've got other NextJS projects running on Netlify properly, so I am sure its just something I overlooked, but the same project deployed to Vercel pretty smoothly. Maybe there's a Netlify vs Vercel post in my future? 😊
In the end, I rolled back to using Gatsby for my blog but I really enjoyed dipping my toes into NextJS a bit, and having the forcing function of converting an existing system over felt like a great way to test the little I learned so far. The benefits of source control, is I can always eject and go back.
Interestingly enough there's been some news from the new kid on the block remix. Check out the Beta Launch Video, you might know them from a little project used by a few react developers here and there. It might be interesting to go through a similar exercise with Remix too, assuming I can find the time.