Skip to content

Cannot find name '$localize' when using vitest without explicit import #32232

@PawelKawula

Description

@PawelKawula

Is this a bug report or a feature request?

  • Bug Report
  • Feature Request

Please provide the steps to reproduce the issue [Bug Report only]

  1. Run ng new vitest-test
  2. Run ng add @angular/localize
  3. Change signal in app.html to use $localize

Please provide the expected behavior vs the actual behavior you encountered [Bug Report only]

I expected succesful run
Instead it only succeeds when i add import '@angular/localize' to app.ts, I can't do it using setupFiles option.
I suspect that it's because it cant pick up this automatic import when it builds and so i can do it only in app.ts, but i dont have to repeat this import for other components.
Adding vitest configuration with globals option enabled doesn't help either.

Please provide a screenshot if possible [Bug Report only]

No response

Please provide the exception or error you saw [Bug Report only]

######/vitest-test>ng test
Automatically searching for and using Vitest configuration file.
Application bundle generation failed. [0.533 seconds] - 2026-01-06T19:48:08.764Z

✘ [ERROR] TS2304: Cannot find name '$localize'. [plugin angular-compiler]

    src/app/app.ts:11:36:
      11 │   protected readonly title = signal($localize`vitest-test`);
         ╵                                     ~~~~~~~~~


Watch mode enabled. Watching for file changes...

Is this a browser-specific issue? If so, please specify the device, browser, and version. [Bug Report only]

It's vitest related

Description [Feature Request only]

No response

Proposed solution [Feature Request only]

No response

Alternatives considered [Feature Request only]

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions