I am generating dynamic links using nuxt content, which worked fine till I updated my nuxt version and nuxt content version.
I'm getting the following error when running npm run build
. This code that is throwing an error is in my nuxt.config.js
.
error:
├─ async routes() { nitro 11:11:07 AM
const { $content } = require('@nuxt/content');
const files = await $content({ deep: true }).only(['path']).fetch();
return files.map((file) => {
let filePath = file.path;
if (filePath === '/pages/index' || filePath.includes('/site')) {
filePath = '/';
} else if (filePath.includes('/pages')) {
filePath = filePath.toString().split('/pages')[1].split('/index')[0];
}
return filePath;
});
} (undefinedms) (TypeError: route.split is not a function)
code:
generate: {
fallback: true,
// Enables router to generate dynamic links (https://content.nuxtjs.org/advanced/)
async routes() {
const { $content } = require('@nuxt/content')
const files = await $content({ deep: true }).only(['path']).fetch()
return files.map((file) => {
let filePath = file.path
if (filePath === '/pages/index' || filePath.includes('/site')) {
filePath = '/'
} else if (filePath.includes('/pages')) {
filePath = filePath.toString().split('/pages')[1].split('/index')[0]
}
return filePath
})
}
},
If I change my code to what it recommends in the docs, I still get the same error..
const { $content } = require('@nuxt/content')
const files = await $content({ deep: true }).only(['path']).fetch()
return files.map(file => file.path === '/pages/index' ? '/' : file.path)
nuxt 3.6.1
nuxt-content 2.7.0