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

typesense-instantsearch-adapter is unfriendly for pure Javascript/ReScript projects #105

Open
sprkv5 opened this issue Apr 8, 2022 · 3 comments

Comments

@sprkv5
Copy link

sprkv5 commented Apr 8, 2022

Description

npm install typesense-instantsearch-adapter provides a dependency that has index.js missing.
This should be fine for TypeScript projects. For pure JavaScript/ReScript projects,
attempting to build the example results in the following error:

var adapter = new TypesenseInstantsearchAdapter(config);
^

TypeError: TypesenseInstantsearchAdapter is not a constructor

Steps to reproduce

  1. mkdir typesense-demo && cd typesense-demo
  2. npm install typesense-instantsearch-adapter
  3. Copy and paste the JavaScript example from : https://typesense.org/docs/guide/search-ui-components.html#walk-through
    // index.mjs -- since we're using ESM
    import TypesenseInstantSearchAdapter from "typesense-instantsearch-adapter";

    const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
    ...
  1. node index.mjs
    file:///C:/Users/User/Projects/typesense-demo/index.mjs:3
    const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
                                          ^

    TypeError: TypesenseInstantSearchAdapter is not a constructor
    ...

Expected Behavior

index.mjs file should run without error

Actual Behavior

I find the following error:

    file:///C:/Users/User/Projects/typesense-demo/index.mjs:3
    const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
                                                                    ^

    TypeError: TypesenseInstantSearchAdapter is not a constructor
    ...

because index.js is missing in the dependency here:
node_modules/typesense-instantsearch-adapter/index.js

Metadata

Typsense Version: 0.22.2

OS: Windows

@jhotujec
Copy link

jhotujec commented May 21, 2023

+1, did you ever manage to solve this?

For now, I managed to get it to work with
import TypesenseInstantSearchAdapter from "typesense-instantsearch-adapter/src/TypesenseInstantsearchAdapter"; instead of import TypesenseInstantSearchAdapter from "typesense-instantsearch-adapter";

@eminos
Copy link

eminos commented Jun 5, 2023

@jhotujec That solution doesn't work for me. I get this error now instead:

2023-06-05 13:55:52 (node:139) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
2023-06-05 13:55:52 (Use `node --trace-warnings ...` to show where the warning was created)
2023-06-05 13:55:52 /app/node_modules/typesense-instantsearch-adapter/src/TypesenseInstantsearchAdapter.js:3
2023-06-05 13:55:52 import { Configuration } from "./Configuration";
2023-06-05 13:55:52 ^^^^^^
2023-06-05 13:55:52 
2023-06-05 13:55:52 SyntaxError: Cannot use import statement outside a module

@jhotujec
Copy link

jhotujec commented Jun 5, 2023

@eminos not sure, I used it like this and it works

import TypesenseInstantSearchAdapter from "typesense-instantsearch-adapter/src/TypesenseInstantsearchAdapter";

const searchAdapter = function (searchParams = {
  query_by: "title",
}) {
  const qtypesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
    server: {
      apiKey: "<your-api-key>",
      nodes: [
        {
          host: "<your-host>",
          path: "",
          port: "443",
          protocol: "https",
        },
      ],
      cacheSearchResultsForSeconds: 0,
    },
    additionalSearchParameters: searchParams
  });
  return qtypesenseInstantsearchAdapter.searchClient;
};

export default searchAdapter;

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

3 participants