medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
26.26k stars 2.67k forks source link

Backend return `addDocuments must be overridden by a child class` when use medusa-plugin-meilisearch@2.0.6 #4159

Closed craftalpian closed 1 year ago

craftalpian commented 1 year ago

Bug report

Describe the bug

When I was using the medusajs-plugin-meilisearch plugin in medusajs which I followed from the following tutorial https://docs.medusajs.com/plugins/search/meilisearch, I noticed that the products I added or updated were not found on my meilisearch server.

When I open the medusa backend, it says "Processing product. created which has 0 subscribers". And when I do the same thing described from https://github.com/medusajs/medusa/issues/3964#issuecomment-1529700523, I run insert into staged_job (id, event_name, data) values ('some_id', ' SEARCH_INDEX_EVENT', '{}') generates "info: Processing SEARCH_INDEX_EVENT which has 1 subscriber warn: This is an empty method: addDocuments must be overridden by a child class"

System information

Medusa version (including plugins): "dependencies": { "@medusajs/admin": "^2.0.2", "@medusajs/cache-inmemory": "^1.8.2", "@medusajs/cache-redis": "1.8.0", "@medusajs/event-bus-local": "^1.8.2", "@medusajs/event-bus-redis": "1.8.0", "@medusajs/medusa": "1.8.1", "@medusajs/medusa-cli": "^1.3.10", "@medusajs/utils": "^1.8.2", "aws-sdk": "^2.1370.0", "axios": "^1.4.0", "cors": "^2.8.5", "joi": "^17.8.3", "medusa-core-utils": "^1.1.39", "medusa-file-minio": "^1.1.5", "medusa-file-s3": "^1.1.11", "medusa-file-spaces": "^1.3.6", "medusa-fulfillment-manual": "^1.1.31", "medusa-interfaces": "^1.3.7", "medusa-payment-manual": "^1.0.16", "medusa-payment-stripe": "^1.1.45", "medusa-plugin-meilisearch": "^2.0.6", "multer": "^1.4.5-lts.1", "multer-s3": "^3.0.1", "typeorm": "0.3.11" }, Node.js version: v16.15.0 Database: postgre Operating system: Windows 11 Browser (if relevant):

Steps to reproduce the behavior

  1. Create some products in medusa admin
  2. Try to find that's product in your meilisearch server
  3. Or you can find with postman

Expected behavior

Every time there is an addition or change to a product in the Medusa admin, the product should also be sent to the meilisearch server which was set up earlier.

Screenshots

image image

image
pevey commented 1 year ago

This is the error you receive from the placeholder search service, before it is overridden by meilisearch or algolia or some future search plugin. It means, basically, that the plugin is not being loaded.

For the newest version of the meilisearch plugin (2.0.6), you will need to upgrade to the latest version of @medusajs/medusa and all its dependencies.

pevey commented 1 year ago

If you need to use an older version of Medusa for some reason, you can try also using a slightly older version of the plugin. Just keep in mind you will also need to revert to an older version of the meilisearch server itself. When it jumped to 1.0, that is when some breaking changes were made.

craftalpian commented 1 year ago

I was upgrade my medusa backend as suggested by you: "dependencies": { "@medusajs/admin": "^2.0.2", "@medusajs/cache-inmemory": "^1.8.2", "@medusajs/cache-redis": "1.8.0", "@medusajs/event-bus-local": "1.9.1", "@medusajs/event-bus-redis": "1.8.3", "@medusajs/medusa": "1.11.0", "@medusajs/medusa-cli": "^1.3.10", "@medusajs/utils": "^1.8.2", "aws-sdk": "^2.1370.0", "axios": "^1.4.0", "cors": "^2.8.5", "joi": "^17.8.3", "medusa-core-utils": "^1.1.39", "medusa-file-minio": "^1.1.5", "medusa-file-s3": "^1.1.11", "medusa-file-spaces": "^1.3.6", "medusa-fulfillment-manual": "^1.1.31", "medusa-interfaces": "^1.3.7", "medusa-payment-manual": "^1.0.16", "medusa-payment-stripe": "^1.1.45", "medusa-plugin-meilisearch": "^2.0.6", "multer": "^1.4.5-lts.1", "multer-s3": "^3.0.1", "typeorm": "^0.3.16" },

When I run insert into staged_job (id, event_name, data) values ('some_id', ' SEARCH_INDEX_EVENT', '{}') query, the result: image

And when I run in postman:

image

The result is:

image
olivermrbl commented 1 year ago

@craftalpian – any chance you can push your project to a repository, that I can run locally?

craftalpian commented 1 year ago

@olivermrbl We have this project in our bitbucket repository, may I invite you to our bitbucket repo?

olivermrbl commented 1 year ago

Sure thang :)

craftalpian commented 1 year ago

@olivermrbl To make it even faster I just added you to a new repo on my github as I just finished mirroring the repo that was bitbucket previously

craftalpian commented 1 year ago

Did you get a chance to take a look at the repo? @olivermrbl

omarghader commented 1 year ago

I got the same issue

olivermrbl commented 1 year ago

@omarghader – can I get you to ensure you've installed the latest version of all Medusa packages in your project?

We are working on improving our versioning, so you don't have to go through this much hassle to make it work.

omarghader commented 1 year ago

Hello @olivermrbl , I got this working by using npm "--force" instead of yarn install Working well with medusa 1.12.0 and meilisearch 2.0.7 now thank you.

lrocher91 commented 1 year ago

Same here, worked after updating plugin packages versions.

Thanks ;)

olivermrbl commented 1 year ago

We've identified the culprit and have a couple of different paths to resolve the issue, so I will close this for now.

peterborodatyy commented 1 year ago

Hello, I'm having same issue in my custom search plugin. It's not recognised as a "searchService" (as I understood, but extends AbstractSearchService from medusajs/utils and implements all methods), and when trying to search, I'm receiving error: "search must be overridden a the child class".

pevey commented 1 year ago

Hello, I'm having same issue in my custom search plugin. It's not recognised as a "searchService" (as I understood, but extends AbstractSearchService from medusajs/utils and implements all methods), and when trying to search, I'm receiving error: "search must be overridden a the child class".

This could be caused by a number of different issues. Changes are, the issue you are having with your custom plugin is not the same as the OP's.

I would start on this page of the docs, toward the bottom in the "Troubleshoot Errors" section. There is a part about deleting certain dependencies and using yarn link to add those to your plugin instead. I would try that first. https://docs.medusajs.com/development/plugins/create

This alleviates the issue that when developing a custom plugin outside of a medusa project folder and outside of a monorepo structure, you end up with circular dependencies, and therefore multiple copies of some medusa-related packages.

Also, simple errors can cause the service not to be recognized. I find that to be very frustrating, because there is no stack trace to help you out. If you use the linking method above and are still having issues, you can try moving your code to a temp file, starting with a skeleton of each function and some console.logs, and then if you can get it working, add back more of the detail bit by bit to see if you can pinpoint the issue.

peterborodatyy commented 1 year ago

I would start on this page of the docs, toward the bottom in the "Troubleshoot Errors" section. There is a part about deleting certain dependencies and using yarn link to add those to your plugin instead. I would try that first. https://docs.medusajs.com/development/plugins/create

Thank you! That was the issue, missed that part in documentation at first.

nikitaSazhinov commented 1 year ago

Hello, having the same issue. I have to use medusa version 1.8.0, I tried to switch the version of the plugin but kept getting either the same or a different error.

Saadchr commented 11 months ago

I've faced the same issue, upgrading to the latest version of the plugin in the backend resolved it. "medusa-plugin-meilisearch": "^2.0.10",