Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'factory' of undefined #63

Open
SHxKM opened this issue Oct 9, 2019 · 3 comments
Open

Cannot read property 'factory' of undefined #63

SHxKM opened this issue Oct 9, 2019 · 3 comments
Labels
bug Something isn't working hacktoberfest

Comments

@SHxKM
Copy link

SHxKM commented Oct 9, 2019

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
    }],
]
@SHxKM
Copy link
Author

SHxKM commented Oct 9, 2019

Moved to top level config and now it's working. Huh.

@TheAlexLichter TheAlexLichter added bug Something isn't working hacktoberfest labels Oct 10, 2019
@TheAlexLichter
Copy link
Member

Looks like the "inline" module options are handled differently / wrongly

@nachoadjust
Copy link

nachoadjust commented Dec 2, 2021

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
}

@nozomuikuta nozomuikuta mentioned this issue Jul 21, 2022
28 tasks
@nozomuikuta nozomuikuta mentioned this issue Dec 14, 2022
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hacktoberfest
Projects
None yet
Development

No branches or pull requests

3 participants