service.list is not a function Error

If you get the following error when using Query to retrieve records of your custom data model:

Terminal
❯service.list is not a function

Why this Error Occurred#

To retrieve records of your data model, Query uses the listX method of your module's service.

For example, if you have a Blog Module and you are trying to retrieve posts, Query will try to call the listPost method of the Blog Module's service. If it doesn't find the method, it will throw the above error.


How to Fix it#

Option 1: Extend Service Factory#

To resolve this error, make sure that your module's service has a listX method that returns the records of your data model.

This method is generated for you if your service extends MedusaService:

src/modules/blog/service.ts
1import { MedusaService } from "@medusajs/framework/utils"2import Post from "./models/post"3
4class BlogModuleService extends MedusaService({5  Post,6}){7}8
9export default BlogModuleService

In the above example, the listPost method is generated for you because the BlogModuleService extends MedusaService.

Option 2: Implement the Method#

If your module is returning data from a third-party service, or you have some custom mechanism to define and manage your data models, then you need to implement the list or just list method in your service.

For example:

src/modules/blog/service.ts
1type BlogModuleOptions = {2  apiKey: string3}4
5export default class BlogModuleService {6  private client7
8  constructor({}, options: BlogModuleOptions) {9    this.client = new Client(options)10  }11
12  async list(13    filter: {14      id: string | string[]15    }16  ) {17    return this.client.getPosts(filter)18    /**19     * Example of returned data:20     * 21     * [22     *   {23     *     "id": "post_123",24     *     "product_id": "prod_321"25     *   },26     *   {27     *     "id": "post_456",28     *     "product_id": "prod_654"29     *   }30     * ]31    */32  }33}

Additional Resources#

Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵