Just recently, I made an update to my next.config.json file in hopes of boosting SEO performance. However, this change has caused some issues with the next-sitemap module, preventing me from building or starting my app.
//next.config.js
const withSitemap = require('next-sitemap');
module.exports = withSitemap({
changefreq: 'weekly',
priority: 0.9,
generateRobotsTxt: true,
});
After adding this snippet of code, attempting to run "next build" resulted in the following error:
> Build error occurred
Error: Cannot find module '/root/node_modules/next-sitemap/dist/cjs/index.js'
at createEsmNotFoundErr (node:internal/modules/cjs/loader:1094:15)
at finalizeEsmResolution (node:internal/modules/cjs/loader:1087:15)
at resolveExports (node:internal/modules/cjs/loader:571:14)
at Module._findPath (node:internal/modules/cjs/loader:645:31)
at Module._resolveFilename (node:internal/modules/cjs/loader:1058:27)
at /root/node_modules/next/dist/server/require-hook.js:113:36
at Module._load (node:internal/modules/cjs/loader:925:27)
at Module.require (node:internal/modules/cjs/loader:1139:19)
at require (node:internal/modules/helpers:121:18)
at Object.<anonymous> (/root/next.config.js:1:21) {
code: 'MODULE_NOT_FOUND',
path: '/root/node_modules/next-sitemap/package.json'
}
I have attempted various troubleshooting steps such as reinstalling node_modules but have not been able to resolve the issue with next-sitemap. Has anyone encountered a similar problem and found a solution?