loader-must-be-exported-in-module-definition - ESLint plugin rules

This rule requires that loader files under a module's loaders directory are registered in the module's loaders array.

Severity#

warn. This rule is enabled in the recommended preset.

What it Targets#

This rule targets loader files under src/modules/<module>/loaders/. It reports a loader file that isn't referenced in the loaders array of the module's definition in index.ts.

The following loader is reported by the rule when it isn't registered in the module definition in index.ts:

src/modules/blog/loaders/my-loader.ts
1import { LoaderOptions } from "@medusajs/framework/types"2
3export default async function myLoader({4  container,5}: LoaderOptions) {6  // ...7}

Instead, register the loader in the module's loaders array in index.ts:

src/modules/blog/index.ts
1import { Module } from "@medusajs/framework/utils"2import BlogModuleService from "./service"3import myLoader from "./loaders/my-loader"4
5export default Module("blog", {6  service: BlogModuleService,7  loaders: [myLoader],8})

Why it's Important#

A loader only runs when it's registered in the module's loaders array. An unregistered loader file is dead code that never executes, which often points to a forgotten registration.

Learn more in the Modules documentation.

Fixable#

This rule isn't auto-fixable.

Turn it Off#

To turn off this rule, set it to off in your ESLint configuration:

eslint.config.ts
1import { defineConfig } from "eslint/config"2import medusa from "@medusajs/eslint-plugin"3
4export default defineConfig([5  ...medusa.configs.recommended,6  {7    rules: {8      "@medusajs/loader-must-be-exported-in-module-definition": "off",9    },10  },11])

Or disable it for a single line using an inline comment:

Code
1// eslint-disable-next-line @medusajs/loader-must-be-exported-in-module-definition2export default async function myLoader() {}
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
⇧↵