medusajs/medusa · warning

Warning: could not parse ${candidate}, using default config

Error message

Warning: could not parse ${candidate}, using default config

What it means

The http-types-generator CLI looks for its config file (http-types.config.json by default) walking up directories. If it finds the file but JSON.parse fails (malformed JSON), it warns and continues with the default/empty config, so custom settings like routes dirs or excludes are silently ignored.

Source

Thrown at packages/cli/http-types-generator/src/config/index.ts:66

  private static _instance: ResolvedHttpTypesConfig | null = null

  /**
   * Walks up the directory tree from `startDir` to find the nearest ancestor
   * (inclusive) that contains `http-types.config.json`. Returns the directory
   * path and parsed contents, or `undefined` if the file is not found.
   */
  private static findConfigFile(
    startDir: string
  ): { dir: string; config: Partial<HttpTypesConfig> } | undefined {
    let dir = startDir
    while (true) {
      const candidate = path.join(dir, Config.CONFIG_FILE_NAME)
      if (existsSync(candidate)) {
        try {
          const raw = readFileSync(candidate, "utf-8")
          return { dir, config: JSON.parse(raw) as Partial<HttpTypesConfig> }
        } catch {
          console.warn(
            `Warning: could not parse ${candidate}, using default config`
          )
          return { dir, config: {} }
        }
      }
      const parent = path.dirname(dir)
      if (parent === dir) break
      dir = parent
    }
    return undefined
  }

  /**
   * Builds a resolved config by deep-merging `override` over DEFAULTS.
   * When `override` is provided the config file is not read and `projectRoot`
   * is set to `process.cwd()`. When omitted, the nearest `http-types.config.json`
   * is found by searching upward from `process.cwd()`; its directory becomes
   * `projectRoot`. Falls back to `process.cwd()` when no config file is found.

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Validate the file with a JSON linter or `npx jsonlint http-types.config.json` and fix syntax errors
  2. Remove trailing commas and comments; use double quotes
  3. Re-run the generator and confirm the warning disappears

Example fix

// before (http-types.config.json)
{ 'srcDir': 'src', }

// after
{ "srcDir": "src" }
Defensive patterns

Strategy: validation

Validate before calling

import { readFileSync } from "fs"
const raw = readFileSync("http-types.config.json", "utf8")
JSON.parse(raw) // throws synchronously if malformed — fix before running generator

Prevention

When it happens

Trigger: A http-types config file with a syntax error: trailing comma, single quotes, unquoted keys, or a BOM/comment.

Common situations: Hand-edited JSON with a trailing comma; file generated by a tool that emits JSON5; merge conflict leftovers.

Related errors


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