in nextjs react static fix ~ read.

Fixing next.js export path to assets issue

Recenlty I had to create a simple report page for one of the tools I built and this page had to be fully static, but reading from a JSON file that I would add to it. I'm not a big specialist in Front End and CSS, but I decided to play around with React + Next.js. Surprisingly everything was done quite fast and I was already celebrating final result the moment I would run next export, but unfortunatelly I discovered that css and javascript was not loaded and I got a very ugly html page :(
The problem was that all static assets were linked in html under /_next/static/ folder path.
After quite some googling and try outs I finally found Github ticket where first sir cargallo gave a nice tip on how to approach this with a plugin, but lower Johnny Dong suggested that ther's a configuration option for this in next.config.js:

module.exports = {
    assetPrefix: ".",
  };

And now you can run npm run export and everything will work like a charm ๐Ÿš€

Happy coding everyone :) ๐ŸŽ‰

comments powered by Disqus
comments powered by Disqus