typesense-instantsearch-adapter
typesense-instantsearch-adapter copied to clipboard
typesense-instantsearch-adapter is unfriendly for pure Javascript/ReScript projects
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
- mkdir typesense-demo && cd typesense-demo
- npm install typesense-instantsearch-adapter
- 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({
...
- 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
+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";
@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
@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;