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

Plugin throws error when running gatsby build #15

Closed
dev-sda1 opened this issue Aug 3, 2022 · 2 comments
Closed

Plugin throws error when running gatsby build #15

dev-sda1 opened this issue Aug 3, 2022 · 2 comments

Comments

@dev-sda1
Copy link
Contributor

dev-sda1 commented Aug 3, 2022

Description

I was attempting to diagnose an issue brought up in #13 , where one of the troubleshooting steps was to run gatsby build. When running this, or npm run build, gatsby-plugin-typesense fails with the following output:

 ERROR #11321  PLUGIN

"gatsby-plugin-typesense" threw an error while running the onPostBuild lifecycle:

exclude.test is not a function

  102 |   // backward compatibility
  103 |   rootDir = rootDir || publicDir
> 104 |   const htmlFiles = await utils.getHTMLFilesRecursively(rootDir, rootDir, exclude)
      |                     ^
  105 |
  106 |   const typesense = new TypesenseClient(server)
  107 |   const newCollectionName = generateNewCollectionName(collectionSchema)

File: node_modules/gatsby-plugin-typesense/gatsby-node.js:104:21



  TypeError: exclude.test is not a function
  
  - utils.js:13 
    [website]/[gatsby-plugin-typesense]/lib/utils.js:13:32
  
  - Array.map
  
  - utils.js:7 Object.exports.getHTMLFilesRecursively
    [website]/[gatsby-plugin-typesense]/lib/utils.js:7:13
  
  - gatsby-node.js:104 Object.exports.onPostBuild
    [website]/[gatsby-plugin-typesense]/gatsby-node.js:104:21
  
  - api-runner-node.js:487 runAPI
    [website]/[gatsby]/src/utils/api-runner-node.js:487:16
  

not finished onPostBuild - 0.131s

Steps to reproduce

I currently run a local copy of the Typesense Server on my machine with the following command:
docker run -i -p 8108:8108 -v/tmp/typesense-server-data/:/data typesense/typesense:0.19.0 --data-dir /data --api-key=redacted --listen-port 8108 --enable-cors

My gatsby-config.js looks like this:

resolve: 'gatsby-plugin-typesense',
    options: {
      rootDir: `${__dirname}/public`,
      exclude: `^(?!.*/20).*$`,
      collectionSchema: {
        name: "posts_v1",
        fields: [
          {
            name: "postTitle",
            type: "string"
          },
          {
            name: "postCategory",
            type: "string"
          },
          // {
          //   name: "tags",
          //   type: "string[]"
          // },
          {
            name: "page_path",
            type: "string"
          },
          {
            name: "page_priority_score",
            type: "int32",
          },
        ],
        default_sorting_field: "page_priority_score",
      },
      server: {
        apiKey: "redacted",
        nodes: [
          {
            host: "localhost",
            port: "8108",
            protocol: "http",
          },
        ],
      },
    }

And i'm using the sample search component provided in the readme:

import * as React from 'react';
import { InstantSearch, SearchBox, Hits, Stats } from "react-instantsearch-dom"
import TypesenseInstantSearchAdapter from "typesense-instantsearch-adapter"

const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
  server: {
    apiKey: "redacted", // Be sure to use the search-only-api-key
    nodes: [
      {
        host: "localhost",
        port: "8108",
        protocol: "http",
      },
    ],
  },
  // The following parameters are directly passed to Typesense's search API endpoint.
  //  So you can pass any parameters supported by the search endpoint below.
  //  queryBy is required.
  additionalSearchParameters: {
    query_by: "postTitle,postCategory",
  },
})
const searchClient = typesenseInstantsearchAdapter.searchClient

export default function SearchInterfaceDesktop() {
  const Hit = ({ hit }) => (
    <p>
      {hit.title} - {hit.description}
    </p>
  )

  return (
      <InstantSearch searchClient={searchClient} indexName="posts_v1">
        <SearchBox />
        <Stats />
        <Hits hitComponent={Hit} />
      </InstantSearch>
  )
}

Expected Behavior

I expect the plugin to build the page schema and complete the build successfully.

Actual Behavior

gatsby-build fails with the error "exclude.test is not a function" under the gatsby-plugin-typesense plugin.

Metadata

Typsense Version: 0.19.0
Plugin Version: 0.3.0

OS: Ubuntu Linux 21.10

@dev-sda1
Copy link
Contributor Author

dev-sda1 commented Aug 3, 2022

Small update: removing the exclude parameter from the plugin's options in gatsby-config.js seems to be a workaround, as the error doesn't show up with it not present.

@dev-sda1
Copy link
Contributor Author

dev-sda1 commented Aug 4, 2022

Resolved in merged PR #16

@dev-sda1 dev-sda1 closed this as completed Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant