Skip to content

I18nJsonLoader throws unhelpful error when JSON syntax is invalid (SWC-compiled NestJS project) #697

@Fighteros

Description

@Fighteros

Describe the bug

🐛 The Problem

When one of the translation files changes or has an error swc stuck on this

G:\<full-path-to-project-dir>\node_modules\rxjs\src\internal\util\reportUnhandledError.ts:21
      throw err;
      ^

I18nError: Invalid JSON file. Please check your JSON syntax.
    at I18nJsonLoader.formatData (.../node_modules/nestjs-i18n/src/loaders/i18n.json.loader.ts:19:15)
    at I18nJsonLoader.parseTranslations (.../i18n.abstract.loader.ts:124:25)

🧪 Environment

nestjs-i18n version "^10.5.1",
Node.js v22.15.1
@swc/cli": "^0.6.0",
@swc/core": "^1.11.29"

⚠️ Issues

With swc, stack traces are less verbose, making it harder to trace.

This causes a full application crash, which is problematic

✅ Expected Behavior
The loader should catch changes
The loader should catch and log errors

Reproduction

Create a NestJS project using SWC compilation Install nestjs-i18n run the app try to change or add to translation files in i18n folder

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (12) x64 AMD Ryzen 5 PRO 4650G with Radeon Graphics
    Memory: 3.03 GB / 13.90 GB
  Binaries:
    Node: 22.15.1 - C:\nvm4w\nodejs\node.EXE
    npm: 10.9.2 - C:\nvm4w\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (136.0.3240.76)

Used Package Manager

npm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions