problems encountered when including next.config.js for sitemap creation in a nextjs application

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?

Answer №1

It is recommended not to modify the next.config.js file directly. Instead, any changes should be made in the next-sitemap.config.js file.

Copy and paste the following code into the next-sitemap.config.js file:

module.exports = {
  changefreq: 'weekly', 
  priority: 0.9,
  generateRobotsTxt: true, 
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Animate the parent container of ng-view in Angular by targeting an element within ng-view

Are you able to use CSS animations to animate a div's background color that is located outside of the ng-view, while using a directive on a $state within the ng-view? The ng-view already has CSS animations for routing. When I try to add animation cl ...

Google App Engine does not properly interpret PHP code when making AJAX requests

I am currently facing an issue with using AJAX request on Google App Engine. In my local development environment, everything works fine and the request is correctly interpreted. However, when I deploy the code to production, the AJAX request renders the co ...

Is there a way to trigger a JavaScript function once AJAX finishes loading content?

I've been utilizing some code for implementing infinite scrolling on a Tumblr blog through AJAX, and it's been performing well except for the loading of specific Flash content. The script for the infinite scroll can be found here. To address the ...

Angular Pagination: Present a collection of pages formatted to the size of A4 paper

Currently, I am working on implementing pagination using NgbdPaginationBasic in my app.module.ts file. import { NgbdPaginationBasic } from './pagination-basic'; My goal is to create a series of A4 size pages with a visible Header and Footer onl ...

Executing an action using nextjs API routes and server-side rendering: a step-by-step guide

I am impressed with the clarity of the next.js documentation on data fetching and dynamic API routes. However, I am curious about the correct method for triggering server-side actions or methods. For example, if a user wants to subscribe to a newsletter by ...

Is it possible to refrain from using the object variable name in an ng-repeat loop?

When utilizing an ng-repeat directive to loop through an array, the syntax requires ng-repeat="friend in friends". Inside the template, you can then use the interpolation operator like this {{friend.name}}. Is there a way to directly assign properties to ...

Troubleshooting 'document is not defined' error while implementing ZEGOCLOUD API in Next.js

Currently, I am in the process of developing a web platform specifically designed for online video conferencing. To achieve this, I have incorporated ZEGOCLOUD as an API with Next.js. However, upon running my program, I encountered an error: #ReferenceErro ...

Importing XML data into a JavaScript variable using jQuery without displaying an alert message

Despite previously asking questions about loading XML into a JS variable, I haven't found a satisfactory solution. In my script, I declare a variable before making an ajax request and then assign the result to that variable. However, this only seems t ...

Improprove the design of the dropdown component using React

One of the challenges I am facing in my project is using multiple dropdowns from semantic-ui-react. Each dropdown needs to have different props, making the code look like this: <div className="wrapper"> <img className="icon" src={iconA} ...

AngularJS encountering unresponsive resources

When setting up my Angular App, I include various resources like this: angular.module('myApp', ['infinite-scroll', 'chieffancypants.loadingBar', 'ngResource']) Next, in the html file: <script type="text/javascr ...

Navigating nested loops within multidimensional arrays

Currently, I am experimenting with nested loops to search through nested arrays in order to find a specific value called "codItem". Below is a test model for the array (as I do not have access to the original fetch request on weekends): let teste = [{ it ...

Refreshing specific iframes without having to reload the entire webpage using jQuery

As the page loads initially, a hidden iframe and other visible ones are present. When a button is clicked, one of the visible iframes needs to be hidden while another becomes visible (with its src attribute set accordingly). The goal is to achieve this wit ...

Updating view with *ngIf won't reflect change in property caused by route change

My custom select bar has a feature where products-header__select expands the list when clicked. To achieve this, I created the property expanded to track its current state. Using *ngIf, I toggle its visibility. The functionality works as expected when cli ...

Locate and filter elements by using the react-testing-library's getAll method

On my page, I have a collection of unique checkbox elements that are custom-designed. Each individual checkbox has the following structure: <div className="checkbox" role="checkbox" onClick={onClick} onKeyPress={onKeyPress} aria-checked={getS ...

Verify if the form has been successfully validated

Here is a simple form using Tag Helper: <form asp-area="Admin" asp-controller="Categories" asp-action="EditCategory" method="post" id="CategoryForm"> <div class="row"> ...

Running a service in Express.js without being dependent on incoming requests

I have a backend application built using nodeJS and express. The architecture consists of two main files, app.js for handling express configuration, controllers, and MongoDB connection, and index.js strictly for server creation. Now, I am looking to imple ...

Instructions on obtaining a distinct daily array from the weather API array that provides a detailed 5-day weather report every 3 hours

Seeking assistance with my weather app development on React using axios with the openweathermap.org API. Currently stuck on getting data formatted in a specific way from the 5-day forecast it provides, totaling 40 reports over the 5 days. The API response ...

html and css code to create a linebreak ↵

I received a JSON response from the server, and within this data is a "return line" in the text. {text: "I appear in the first line ↵ and I appear in the second line"} However, when I try to display this on an HTML page, the "return line" does not show ...

Having trouble dynamically assigning the ng-model attribute

I am trying to populate the ArrayINeed array, which is the object I need to pass back to the API call. Currently, I am getting undefined for "ConfirmedTrackingReferenceNumbers": Dc.ArrayINeed. Despite researching various posts online and on SO, I have been ...

Leveraging the outcome of a for loop in order to set a condition within an else if statement

How can I condition my third else if statement based on the result of a for loop? //If player clicks centre on first move go in corner square if (current[4] === playerToken && this.state.stepNumber === 1) { let move = c ...