meilisearch / gatsby-plugin-meilisearch

A plugin to index your Gatsby content to Meilisearch based on graphQL queries
MIT License
40 stars 4 forks source link

Cannot read properties of undefined (reading 'length') #149

Closed tukiminya closed 2 years ago

tukiminya commented 2 years ago

I tried to do an Indexes using gatsby-plugin-meilisearch with a yarn build, but I got the following error Anyone else with the same error?

Error


 ERROR 

Cannot read properties of undefined (reading 'length')

success gatsby-plugin-meilisearch - 0.054s - Failed to index to Meilisearch

package.json:

{
  "name": "test",
  "version": "1.0.0",
  "private": true,
  "description": "test",
  "author": "tukimi",
  "keywords": [
    "gatsby"
  ],
  "scripts": {
    "dev": "gatsby develop",
    "start": "gatsby develop",
    "build": "gatsby build",
    "serve": "gatsby serve",
    "clean": "gatsby clean"
  },
  "dependencies": {
    "@hcaptcha/react-hcaptcha": "^1.4.1",
    "@headlessui/react": "^1.6.5",
    "axios": "^0.27.2",
    "daisyui": "^2.17.0",
    "gatsby": "^4.17.1",
    "gatsby-plugin-image": "^2.17.0",
    "gatsby-plugin-manifest": "^4.17.0",
    "gatsby-plugin-meilisearch": "^0.1.2",
    "gatsby-plugin-sharp": "^4.17.0",
    "gatsby-plugin-sitemap": "^5.17.0",
    "gatsby-remark-component": "^1.1.3",
    "gatsby-remark-images": "^6.17.0",
    "gatsby-remark-relative-images": "^2.0.2",
    "gatsby-source-filesystem": "^4.17.0",
    "gatsby-transformer-remark": "^5.17.0",
    "gatsby-transformer-sharp": "^4.17.0",
    "react": "^18.1.0",
    "react-dom": "^18.1.0",
    "react-helmet": "^6.1.0",
    "rehype-react": "^7.1.1"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.7",
    "gatsby-plugin-postcss": "^5.17.0",
    "postcss": "^8.4.14",
    "tailwindcss": "^3.1.4"
  }
}

gatsby-config.js

module.exports = {
  siteMetadata: {
    title: `test`,
    siteUrl: `https://example.com`
  },
  plugins: [
    "gatsby-plugin-image",
    "gatsby-plugin-sitemap",
    "gatsby-plugin-postcss",
    {
      resolve: 'gatsby-plugin-manifest',
      options: {
        "icon": "./src/images/symbol.png"
      }
    },
    "gatsby-plugin-sharp",
    {
      resolve: "gatsby-transformer-remark",
      options: {
        plugins: [
          "gatsby-remark-relative-images",
          {
            resolve: "gatsby-remark-images",
            options: {
              maxWidth: 840,
              linkImagesToOriginal: false,
            }
          },
          {
            resolve: "gatsby-remark-component",
            options: { components: ["alert", "warning", "info"] }
          }
        ]
      }
    },
    "gatsby-transformer-sharp",
    {
      resolve: 'gatsby-source-filesystem',
      options: {
        "name": "images",
        "path": "./src/images/"
      },
      __key: "images"
    },
    {
      resolve: 'gatsby-source-filesystem',
      options: {
        "name": "pages",
        "path": "./src/pages/"
      },
      __key: "pages"
    },
    {
      resolve: 'gatsby-source-filesystem',
      options: {
        "name": "article",
        "path": `${__dirname}/article/`
      }
    },
    {
      resolve: 'gatsby-plugin-meilisearch',
      options: {
        host: 'http://localhost:7700',
        apiKey: 'masterKey',
        indexes: [
          {
            indexUid: 'testIndex',
            transformer: (data) => {
              data.allMarkdownRemark.edges.map(({ node }) => {
                return {
                  id: node.id,
                  title: node.frontmatter.title,
                  content: node.rawMarkdownBody,
                  slug: '/articles' + node.fields.slug,
                }
              })
            },
            query: `
            query IndexQuery {
              allMarkdownRemark {
                edges {
                  node {
                    id
                    rawMarkdownBody
                    frontmatter {
                      title
                    }
                    fields {
                      slug
                    }
                  }
                }
              }
            }
            `,
          },
        ],
      },
    }
  ],
  trailingSlash: "never"
};
bidoubiwa commented 2 years ago

Hey @kr-tukimi, The only place where we use length is in these lines

        // Index data to Meilisearch
        const enqueuedUpdates = await index.addDocumentsInBatches(
          transformedData,
          batchSize
        )

        if (enqueuedUpdates.length === 0) {
          throw getErrorMsg(
            'Nothing has been indexed to Meilisearch. Make sure your documents are transformed into an array of objects'
          )
        }

This means something must have gone wrong during indexation and the addDocumentsInBatches did not throw the error properly. Do you have access to your Meili logs? If yes can you take a look to find maybe some /documents routes that are not in 204? If everything seems normal, could you fetch your tasks using this route and find the onces that are adding the documents and copy paste them here?

tukiminya commented 2 years ago

Hello @bidoubiwa,

Sorry, I don't know where the Meilisearch logs are... Could you please tell me the path?

tukiminya commented 2 years ago

I was getting this error in the Docker console:

[2022-07-11T11:28:51Z INFO  actix_web::middleware::logger] 172.17.0.1 "DELETE /indexes/test HTTP/1.1" 202 114 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)" 0.003346

The index seems to have been deleted after the build failed.

tukiminya commented 2 years ago

Here is the result of fetching the task: (The reason there are two errors is because I tried twice)

{
  "results": [
    {
      "uid": 1,
      "indexUid": "test",
      "status": "failed",
      "type": "indexDeletion",
      "details": {
        "deletedDocuments": 0
      },
      "error": {
        "message": "Index `test` not found.",
        "code": "index_not_found",
        "type": "invalid_request",
        "link": "https://docs.meilisearch.com/errors#index_not_found"
      },
      "duration": "PT0.009537100S",
      "enqueuedAt": "2022-07-11T11:28:51.9235144Z",
      "startedAt": "2022-07-11T11:28:51.9265978Z",
      "finishedAt": "2022-07-11T11:28:51.9361349Z"
    },
    {
      "uid": 0,
      "indexUid": "test",
      "status": "failed",
      "type": "indexDeletion",
      "details": {
        "deletedDocuments": 0
      },
      "error": {
        "message": "Index `test` not found.",
        "code": "index_not_found",
        "type": "invalid_request",
        "link": "https://docs.meilisearch.com/errors#index_not_found"
      },
      "duration": "PT0.044219200S",
      "enqueuedAt": "2022-07-11T11:16:42.3955833Z",
      "startedAt": "2022-07-11T11:16:42.4054709Z",
      "finishedAt": "2022-07-11T11:16:42.4496901Z"
    }
  ]
}
bidoubiwa commented 2 years ago

Hey @kr-tukimi Which version of Meilisearch are you using? v0.27.0 or v0.28.0 ?

tukiminya commented 2 years ago

Hi @bidoubiwa I was using v0.27.0 when I opened this issue.

bidoubiwa commented 2 years ago

I can see that the index you provided in your config file is indexUid: 'testIndex', but the one in the task is "message": "Index test not found.",

Is this because you changed the name? Or is it part of the bug?

Are you still using v0.27.0 for the moment ?

tukiminya commented 2 years ago

As for the index ID, I originally used a different ID, but when I submitted the issue, I overwrote it with another one, and it is a blur of the notation. Sorry about that...

I upgraded the version from v0.27.0 to v.0.28.0 and tried to build again, but the error occurs in a place unrelated to Meilisearch. I will report back with results once the error is resolved.

bidoubiwa commented 2 years ago

Closing this, if it is still an issue feel free to re-open