feed-module
feed-module copied to clipboard
Cannot read property 'factory' of undefined
What is wrong with this config? it follows the docs but i get:
TypeError: Cannot read property 'factory' of undefined
modules: [
['@nuxtjs/feed', {
path: '/feed.xml', // The route to your feed.
async create(feed) {
feed.options = {
title: 'Some blog RSS Feed',
link: 'https://someblog.sh/feed.xml',
description: 'Latest entries on Some Blog'
}
const posts = await (axios.get(`${process.env.HEROKU_BACKEND_API_URL}/api/posts`)).data
posts.forEach(post => {
feed.addItem({
title: post.title,
id: post.slug,
link: post.slug,
content: post.content
})
})
},
cacheTime: 1000 * 60 * 15, // How long should the feed be cached
type: 'rss2', // Can be: rss2, atom1, json1
}],
]
Moved to top level config and now it's working. Huh.
Looks like the "inline" module options are handled differently / wrongly
Hello! We are experimenting the same error, but with the top level config:
(node:36814) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'factory' of undefined
at ModuleContainer.feed (/company-site/node_modules/@nuxtjs/feed/lib/module.js:24:27)
at ModuleContainer.addModule (/company-site/node_modules/@nuxt/core/dist/core.js:235:34)
at /company-site/node_modules/@nuxt/utils/dist/utils.js:1846:43
at async ModuleContainer.ready (/company-site/node_modules/@nuxt/core/dist/core.js:55:5)
at async Nuxt._init (/company-site/node_modules/@nuxt/core/dist/core.js:715:5)
(Use `node --trace-warnings ...` to show where the warning was created)
- Nuxt Version: 2.14.5
- Nuxt Feed Version: 1.1.0 (we tried 2.0.0, but we run into this issue)
I cannot create a sandbox, because of the project size.
I am sharing the approach we are taking, which is the next best thing I can do.
Any help to understand the issue/ solve it will be greatly appreciated!
Thank you!
const create = async (feed, [ stories, locale ]) => {
feed.options = {
title: "Blog",
link: `${env.baseUrl}${locale}.rss`,
description: "description"
}
for (const post of stories) {
try {
const cardImage = isObject(post.content.cardImage) ? post.content.cardImage.filename : post.content.cardImage
let transformedImage = ""
if (isString(cardImage)) {
transformedImage = storyblokImageTransform(cardImage, { width: 600, height: 0 })
}
feed.addItem({
title: post.content.pageTitle,
link: `${env.baseUrl}blog/${post.slug}/`,
description: post.content.pageByline,
image: transformedImage,
date: new Date(post.published_at)
})
} catch (error) {
showMessage(`[RSS Feeds generation] Failed to add item to RSS: ${error}`, { type: "error" })
}
}
}
const feed = async () => {
const feeds = []
const locales = ["en"]
showMessage("[RSS Feeds generation] Starting")
for (let locale of locales) {
try {
// Get all elements needed for the feed in this locale
const { data } = await storyblok.get("cdn/stories", {
starts_with: `${locale}/blog`,
stories_only: true,
is_startpage: 0,
per_page: PER_PAGE,
filter_query: {
component: {
in: 'CBlogPost'
}
}
})
feeds.push({
path: `/rssfeeds/${locale}/blog/all.rss`,
cacheTime: 1000 * 60 * 15,
type: "rss2",
create,
data: [data.stories, locale]
})
} catch (error) {
showMessage(`[RSS Feeds generation] Failed to generate RSS: ${error}`)
}
}
showMessage("[RSS Feeds generation] Ended")
return feeds
}
const modules = [
...
"@nuxtjs/feed" // Side question: We used to have the module in "buildModules". But In your docs it appears in `modules` in all cases. Does it alter the result where to use it when it's only needed during `nuxt generate` ?
]
module.exports = {
...,
modules,
feed
}