Skip to content

Cannot access ambient const enums when 'isolatedModules' is enabled (v4) #1787

Description

@jl75

Description

Thank you for a great library!

We've just upgraded from v3 to v4, and now we're running into a build problem. We use the error handling described in your documentation: [https://next-intl.dev/docs/usage/configuration#error-handling], and we are checking error codes with if (error.code === IntlErrorCode.MISSING_MESSAGE). We now get the following build error: Type error: Cannot access ambient const enums when 'isolatedModules' is enabled, obviously caused by the change from: declare enum IntlErrorCode to declare const enum IntlErrorCode. In your documentation on error handling, the enum is used at runtime, which is very useful. But v4 made this use impossible by the conversion to a const enum.

I see several potential "solutions":

  • Disable isolatedModules, which is a no-go for our Next.js project;
  • Bypass the definition of IntlErrorCode and define our own, which is undesirable;
  • Redefine the IntlErrorCode enum in your library (overwrite, which is also undesirable).

Do you see a feasible alternative, or would you be willing to revert to the old declaration, so we can use the enum both at compile time and at runtime?

Thanks in advance.

Verifications

Mandatory reproduction URL

https://github.com/jl75/next-intl-ambient-enum-bug/tree/main

Reproduction description

Steps to reproduce: clone repository, install and build.

Expected behaviour

Build without errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions