Skip to content

loadTranslations fallback leads to infinite loop: "ERR_INVALID_TYPESCRIPT_SYNTAX" #2977

@dupasj

Description

@dupasj

Search terms

loadTranslations, ERR_INVALID_TYPESCRIPT_SYNTAX, infinite recursion, Windows, locales, require, en.cjs

Expected Behavior

  • loadTranslations("en") should load the English translation file and fallback gracefully if a locale is missing.
  • IDE should not flag i18n strings like i18n.file_0_changed_restarting() as unresolved.
Image

Actual Behavior

  • pnpm build works and doesn't throw errors.
  • All the i18n values are flagged as unresolved but my IDE (IntelliJ)
  • If I run pnpm test, I have a recursive loop in loadTranslation in src/lib/internationalization/internationalization.ts:69:16:
/**
 * Load TypeDoc's translations for a specified language
 */
export function loadTranslations(lang: string): Record<string, string> {
    // Make sure this isn't abused to load some random file by mistake
    ok(
        /^[A-Za-z-]+$/.test(lang),
        "Locale names may only contain letters and dashes",
    );
    try {
        return req(`./locales/${lang}.cjs`);
    } catch {
        return loadTranslations("en"); // <-- HERE
    }
}

Debug

I edited the try/catch to get the error details:

/**
 * Load TypeDoc's translations for a specified language
 */
export function loadTranslations(lang: string): Record<string, string> {
    // Make sure this isn't abused to load some random file by mistake
    ok(
        /^[A-Za-z-]+$/.test(lang),
        "Locale names may only contain letters and dashes",
    );
    try {
        return req(`./locales/${lang}.cjs`);
    } catch (e) {
        console.log(e)// SyntaxError [ERR_INVALID_TYPESCRIPT_SYNTAX]
        return loadTranslations("en");
    }
}

Environment

  • Typedoc version: f60f0a4
  • TypeScript version: 5.8.3 (from the project typescript version inthe package)
  • Node.js version: 23.6.0
  • OS: Windows 11 (french)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions