medusajs/medusa · error · Error

Invalid module name "${name}". Module names must be alpha nu

Error message

Invalid module name "${name}". Module names must be alpha numeric and may contain an underscore

What it means

During type generation (gml/medusa dev typegen), module names are turned into TypeScript identifiers, so they must match /^[a-zA-Z_][0-9a-zA-Z_]*$/. Names with dashes, dots, spaces, or leading digits throw.

Source

Thrown at packages/core/utils/src/common/validate-module-name.ts:21

 * a lot of code, types under the hood using the module name we
 * have ensure that each module name is variable safe.
 *
 * Ofcourse, we can transform the module name to a variable safe value,
 * but that might result into naming conflicts. For example: There are
 * two module named as
 *
 * - sanity-products
 * - sanity_products
 *
 * After transforming them, they will endup with the same output. This is
 * a very simple example, but cases like these will lead to naming
 * conflicts, so its better to use the names as it is and restrict
 * them to be variable safe
 */
const RE = /^[a-zA-Z_][0-9a-zA-Z_]*$/
export function validateModuleName(name: string) {
  if (!RE.test(name)) {
    throw new Error(
      `Invalid module name "${name}". Module names must be alpha numeric and may contain an underscore`
    )
  }
}

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Rename the module key to alphanumeric/underscore, e.g. myModule or my_module
  2. Keep the npm package kebab-case in `resolve` but set `key` to an identifier-safe name

Example fix

// before
modules: [{ resolve: "./src/modules/my-blog", key: "my-blog" }]
// after
modules: [{ resolve: "./src/modules/my-blog", key: "myBlog" }]
Defensive patterns

Strategy: validation

Validate before calling

if (!/^[a-zA-Z_][0-9a-zA-Z_]*$/.test(moduleKey)) throw new Error('module key must be identifier-safe')

Type guard

const isIdentifierSafe = (s: string): boolean => /^[a-zA-Z_][0-9a-zA-Z_]*$/.test(s)

Prevention

When it happens

Trigger: Naming a custom module declaration key like "my-module" or "1catalog" then running `medusa db generate`/typegen; the key would produce an invalid generated variable name.

Common situations: Copying npm-style kebab-case package names as module keys, or renaming modules without checking identifier rules.

Related errors


AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27). Data as JSON: /api/errors/78f8bf490d7f14c1. Report an issue: GitHub.