Having issues with sitemap.xml functionality in Next.js post build

I've encountered an issue while working on my Next.js project. Everything runs smoothly in development, but once I build the project for production, the /sitemap.xml URL doesn't return any data.

To address this problem, I created a sitemap.ts file within the /app directory:

import { MetadataRoute } from 'next'
import { getAllNews } from '../app/libs/api/news' 

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {

  let news = await getAllNews();

  console.log(news)
  return [ ...news]
}

Could there be any specific configurations or common issues that I should be aware of when it comes to static generation and sitemap generation in Next.js?

Answer №1

To improve your experience with news feeds, consider utilizing the map function in processing the list of news items.

const updatedNews = news.map(newsItem => ({
  url: `${process.env.NEXT_PUBLIC_BASE_URL}/news/${newsItem.slug}`,
  lastUpdated: newsItem.updatedAt,
}));

return updatedNews;

Ensure that you have correctly set the Environment variable for NEXT_PUBLIC_BASE_URL based on your Operating System requirements.

If the issue persists, please provide more detailed logs for further assistance.

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

Analyzing the Object Property Levels along with the Availability of Optional Properties

I'm in a bit of uncharted territory here, looking for some guidance on whether what I need actually exists... Scenario: I'm working with Firestore to store data and constructing a custom hook (React 16.8) that can be used whenever I want to save ...

Eliminate any spaces surrounding the text within the div tag

Is it possible to eliminate extra space at the end of text using CSS (or possibly JS)? I've experimented with various display properties, but none seem to be effective. I need to dynamically insert a blink-div at the conclusion of a multi-line sentenc ...

Stack required: \ Error, this is a new one to me

throw err; ^ Error: The module './C:\Users\domri\OneDrive\Desktop\Repositories\Discord Bot\commands\test/ping.js' cannot be located The error seems to be originating from this section of the code const ...

Can Angular JS handle Object Logging?

Exploring the possibility of using Angular JS with MVC 5.0, I am looking for a way to log the complete class Object into a database whenever an Insert/Edit/Delete operation is performed. Is there a library available in Angular JS that can help serialize ...

What is the best way to elucidate this concept within the realm of TypeScript?

While diving into my ts learning journey, I came across this interesting code snippet: export const Field:<T> (x:T) => T; I'm having trouble wrapping my head around it. It resembles the function definition below: type myFunction<T> = ...

Automatically adjusting input box size and position in real-time

I am working on a form that includes a button and an input field. When the user clicks on the button "ADD MORE FIELDS," I want to dynamically generate a new input box. Although I have tried using code from this jsfiddle link and it works, my goal is to ach ...

Implementing JavaScript to add elements to class

Is there a way to use JavaScript to dynamically add classes to elements? <div class="col-md-4 col-xs-6 work-item web-design" id="SetCategory"> . . <script> document.getElementById("SetCategory").classList.add('{{ $category->nam ...

Here's how you can combine several elements from one array and assign them to the first element of another array:

I'm working with an array that looks like this: public static readonly List: Array<any> = [ { name: 'CCS', link: 'Dummy link1' }, { name: 'CCR', link: 'Dummy link2' }, { name: 'PM', ...

Transferring information to a controller using ajax in ASP.NET Core

I am encountering an issue with sending data to the controller through ajax. The value goes as "null". Can someone please assist me with this? Here are my HTML codes: <div class="modal fade" id="sagTikMenuKategoriGuncelleModal" data ...

Is there a way to recursively convert property types from one to another in an object that contains optional properties?

The scenario: I am currently working with MongoDB and a REST API that communicates using JSON. MongoDB uses objects instead of identifiers for documents, but when these objects are stringified (such as in a response body), they get converted into strings. ...

Troubleshooting a Blank Screen Issue when Deploying React and Ruby on Rails on Heroku

My Heroku test environment features a Ruby on Rails backend and React frontend combination. After pushing out some changes, the test environment is now displaying either a blank screen with a JavaScript error message or another error related to certain p ...

Whenever I try to download express using npm install, I encounter a checksum

I currently have node version 0.10.30 and npm version 1.4.21 installed on my system. When I run the following command: npm install express I encounter the following error: Error: shasum check failed for /tmp/npm-4273-g1Rb0gCE/registry.npmjs.org/express/ ...

Easily pass parameters to an event handler in a stateless component without the need to create a new reference of the handler every time the component re-re

// @flow import React from 'react'; import Input from 'components/Input'; import logo from 'assets/images/svg/logo.svg'; import styles from './style.module.css'; type TodoMethod = string => void; type TodoProps ...

Exploring the vueJS canvas life cycle and transitioning between components

Struggling with displaying Vue components that contain a canvas with different behaviors. Looking to switch components using v-if and passing different properties. Here's a small example: Currently, when switching from 'blue' to 'red ...

Updating data scope in AngularJS using $http request not functioning properly

I am facing an issue where the $scope.user_free_status is not updating when I set a user free, but works perfectly fine when I unset the parameter. It's strange that I need to reload the page in one case and not the other. The data fetched is stored i ...

Return true for cucumber datatable in typescript without fail

I am facing an issue where the following step definition always returns true even for incorrect data from the dataTable. Can someone assist me in correcting the syntax in TypeScript with Chai assertions? Then(/^Verify the following details in report$/, a ...

The variable 'string' has been declared, but it is never utilized or accessed

Currently delving into Typescript and facing an early error. Despite following a tutorial, I'm encountering multiple errors that I have attempted to comment out. Would greatly appreciate it if someone could shed some light on why these errors are occu ...

A step-by-step guide on incorporating the C3 Gauge Chart into an Angular 5 application

I have been attempting to incorporate the C3 Gauge Chart from this link into a new Angular 5 application. Below is my code within chart.component.ts : import { Component, OnInit, AfterViewInit } from '@angular/core'; import * as c3 from &apos ...

What is the best way to keep a checkbox unchecked after clicking cancel?

I'm working on a bootbox script that triggers a customized alert. I need the checkbox that triggers the alert to be unchecked when the user clicks cancel. Here is the checkbox when it's checked <div class="checkbox"> <label> ...

Converting JSON data into a JavaScript array and storing it in a variable

Currently, I am delving into the world of JavaScript and my instructor has assigned a task that involves utilizing information from a JSON file within our JavaScript code. The issue I'm facing is deciphering how to effectively convert the JSON data i ...