nativescript-community / algolia

NativeScript plugin for Algolia search.
Other
2 stars 2 forks source link

CompletionHandler was not found #2

Closed shiv19 closed 3 years ago

shiv19 commented 3 years ago

I've been getting this warning during webpack builds.

I'm using Webpack 5 with NativeScript 8

WARNING in ./node_modules/@nativescript-community/algolia/algolia.android.js 12:38-55
export 'CompletionHandler' (imported as 'CompletionHandler') was not found in './algolia-index' (possible exports: AlgoliaIndex)
 @ ./app/pages/findRecipes/findRecipes-page.js 5:0-58 142:26-33
 @ ./app/ sync .(xml|js|s?css)$ ./pages/findRecipes/findRecipes-page.js
 @ ./app/__@nativescript_webpack_virtual_entry_javascript__ 3:16-89

On the findRecipes page, I'm just importing it like this

import { Algolia } from '@nativescript-community/algolia';
shiv19 commented 3 years ago

algolia-index.android.ts file did not have an export for Completion Handler.

I added

export const CompletionHandler;

to this file.

And I changed the way it is exported to

export const CompletionHandler = com.algolia.search.saas.CompletionHandler.extend({
    init() {
        return global.__native(this);
    },
    requestCompleted(content, error) {
        if (error) {
            return this.handler(null, error);
        }
        return this.handler(JSON.parse(content.toString()));
    }
});

That fixed it for me.