Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ng extract-i18n crashes when consuming a library that uses $localize and has sourceMaps #64379

@daiscog

Description

@daiscog

Which @angular/* package(s) are the source of the bug?

localize

Is this a regression?

Yes

Description

After upgrading to Angular 20, we're seeing ng extract-i18n fail.

We are consuming components from 3rd party packages created with ng-packagr (same Angular version) and those components use $localize in their typescript files.

Please provide a link to a minimal reproduction of the bug

https://github.com/daiscog/angular-20-extract-i18n-issue

Please provide the exception or error you saw

[error] TypeError: Cannot read properties of undefined (reading 'startOfLinePositions')
    at MessageExtractor.getOriginalLocation (file:///.../node_modules/@angular/localize/tools/bundles/chunk-TZHZOBVD.js:183:41)
    ...

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 20.3.5
Node: 20.19.0
Package Manager: npm 10.8.2
OS: darwin arm64
    

Angular: 20.3.4
... common, compiler, compiler-cli, core, forms, localize
... platform-browser, router

Package                      Version
------------------------------------
@angular-devkit/architect    0.2003.5
@angular-devkit/core         20.3.5
@angular-devkit/schematics   20.3.5
@angular/build               20.3.5
@angular/cli                 20.3.5
@schematics/angular          20.3.5
rxjs                         7.8.2
typescript                   5.9.3
zone.js                      0.15.1

Anything else?

Previously reported in #63528, although nothing to do with nx.

The minimal example above contains an example 3rd party package (installed from a local .tgz file) which contains the following component:

@Component({
  selector: 'lib-foo',
  template: `<p>{{foo}}</p>`,
})
export class Foo {
  readonly foo = $localize`:message@@foo-works:Foo works!`;
}

This is exported via the main index.ts file. The lib was built using ng-packagr and npm pack ran in the result to create the .tgz file, which is then installed in the example repo.

I've monkey-patched node_modules/@angular/localize/tools/bundles/chunk-TZHZOBVD.js with the following immediately before the line where the error was thrown:

    if (!originalSourceFile) {
      console.log('Looking for ' + originalStart.file);
      console.log(originalStart.file, location);
      process.exit(1);
    }

...and that logs this (paths snipped for brevity):

Looking for .../example/libs/foo/src/lib/foo/foo.ts
.../example/libs/foo/src/lib/foo/foo.ts {
  start: { line: 36527, column: 17 },
  end: { line: 36527, column: 49 },
  file: '.../example/main-D7LCOSUQ.js',
  text: '`:message@@foo-works:Foo works!`'
}

Note that there is no such file as libs/foo/src/lib/foo/foo.ts in this project - this is actually the relative path to the file in the 3rd party lib project that was packaged with ng-packagr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: i18nIssues related to localization and internationalization

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions