N
Nuxt4d ago
Evan M

Nuxt Sitemap Issues

Nuxt and nuxt sitemap versions: └── @nuxtjs/[email protected] └── [email protected] Error: ERROR Could not load @nuxtjs/sitemap. Is it installed? 9:38:53 AM at loadNuxtModuleInstance (node_modules/@nuxt/kit/dist/index.mjs:2472:11) at async installModule (node_modules/@nuxt/kit/dist/index.mjs:2395:67) at async initNuxt (node_modules/nuxt/dist/shared/nuxt.BoHAox-C.mjs:5339:5) at async loadNuxt (node_modules/nuxt/dist/shared/nuxt.BoHAox-C.mjs:5527:5) at async loadNuxt (node_modules/@nuxt/kit/dist/index.mjs:2642:19) at async Object.run (node_modules/@nuxt/cli/dist/chunks/prepare.mjs:30:18) at async runCommand (node_modules/citty/dist/index.mjs:316:16) at async runCommand (node_modules/@nuxt/cli/dist/shared/cli.TH4BiEd5.mjs:189:10) at async Object.setup (node_modules/@nuxt/cli/dist/chunks/add2.mjs:67:5) at async runCommand (node_modules/citty/dist/index.mjs:288:5) at async runCommand (node_modules/citty/dist/index.mjs:307:11) at async runCommand (node_modules/citty/dist/index.mjs:307:11) at async runMain (node_modules/citty/dist/index.mjs:445:7) Solutions Tried - Manually installing @nuxtjs/sitemap - Clearing cache, deleting package lock, deleting node modules
4 Replies
kapa.ai
kapa.ai4d ago
Hi @Evan M. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in your question and the knowledge sources available, it appears you're encountering an issue with the @nuxtjs/sitemap module in a Nuxt 3 project. Let me address this problem: The error message suggests that Nuxt is unable to load the @nuxtjs/sitemap module. This is likely due to a compatibility issue between the versions you're using. According to the Stack Overflow post, the @nuxtjs/sitemap module version 2.x is intended for Nuxt 2, not Nuxt 3. You're using Nuxt 3.15.2, which is not compatible with @nuxtjs/[email protected]. For Nuxt 3, it's recommended to use a different sitemap solution. Here are a couple of options: 1. Use Nuxt Simple Sitemap: As mentioned in the Nuxt Content documentation, you can use Nuxt Simple Sitemap, which integrates well with Nuxt 3 and Nuxt Content's document-driven mode. 2. Implement your own sitemap: The same Nuxt Content documentation provides a guide on how to create your own sitemap using the sitemap library. This approach involves creating a server route that generates the sitemap dynamically. Here's a basic example of how you might implement your own sitemap:
import { serverQueryContent } from '#content/server'
import { SitemapStream, streamToPromise } from 'sitemap'

export default defineEventHandler(async (event) => {
// Fetch all documents
const docs = await serverQueryContent(event).find()
const sitemap = new SitemapStream({
hostname: '<https://example.com'>
})

for (const doc of docs) {
sitemap.write({
url: doc._path,
changefreq: 'monthly'
})
}
sitemap.end()

return streamToPromise(sitemap)
})
import { serverQueryContent } from '#content/server'
import { SitemapStream, streamToPromise } from 'sitemap'

export default defineEventHandler(async (event) => {
// Fetch all documents
const docs = await serverQueryContent(event).find()
const sitemap = new SitemapStream({
hostname: '<https://example.com'>
})

for (const doc of docs) {
sitemap.write({
url: doc._path,
changefreq: 'monthly'
})
}
sitemap.end()

return streamToPromise(sitemap)
})
To implement this, you would need to install the sitemap library and create a server route for your sitemap. If you decide to stick with @nuxtjs/sitemap, you'll need to downgrade to Nuxt 2, which is not recommended as Nuxt 3 is the current stable version with many improvements and features. Remember to always check the compatibility of modules with your Nuxt version before installation. If you continue to face issues, consider opening a discussion on the Nuxt GitHub repository for more specific assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4d ago
<@157534667791269889> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Evan M
Evan MOP4d ago
Nuxt sitemap v7.2.0 is for nuxt 3, not nuxt 2.. It should be working.
РеалАлек
Same here i have problems with the latest Update.

Did you find this page helpful?