Skip to content

library builder silently emits an empty package when internal imports use paths aliases or subpath imports #34813

Backlog

Description

@ldt-fweichert

Command

build

Is this a regression?

No

Description

When a library uses TypeScript paths aliases or package.json subpath imports (#src/*) for its own internal files, @angular/build:library treats those imports as external. The build succeeds without any warning, but the output package only contains re-exports pointing at source files that don't exist in dist/:

// dist/my-lib/fesm2022/my-lib.mjs
export * from "src/lib/my-lib";
export * from "src/lib/theme.service";

The .d.ts bundle has the same problem, so the package is broken for every consumer.

The cause is the resolver in pipeline/bundler.js, which marks every specifier that doesn't start with . or / as external without checking whether it resolves to a file in the library. @angular/build:ng-packagr behaves the same way (isExternalDependency in flatten/rolldown.js).

Aliases for internal imports are a common setup, and the application builder supports them. It would be great if the library builder resolved them as well: either paths from the library's tsconfig, or the imports field of the library's package.json, which seems like the more standards-based option. If that's out of scope, the build should at least fail with a clear error instead of emitting an empty package.

Minimal Reproduction

  1. ng new ws --no-create-application && cd ws && ng g library my-lib
  2. Add to projects/my-lib/tsconfig.lib.json:
    "compilerOptions": { "paths": { "src/*": ["./src/*"] } }
  3. In projects/my-lib/src/public-api.ts, change the export to export * from 'src/lib/my-lib';
  4. ng build my-lib
  5. Look at dist/my-lib/fesm2022/my-lib.mjs: it contains only the re-export, not the component.

Same result with "imports": { "#src/*": "./src/*.ts" } in the library's package.json and #src/... specifiers.

Exception or Error

None. The build reports success.

Your Environment

Angular CLI       : 22.3.0
Angular           : 22.3.0
Node.js           : 22.23.5
Package Manager   : npm 10.9.9
Operating System  : linux x64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 22.3.0            │ ^22.3.0           │
│ @angular/cli              │ 22.3.0            │ ^22.3.0           │
│ @angular/common           │ 22.3.0            │ ^22.3.0           │
│ @angular/compiler         │ 22.3.0            │ ^22.3.0           │
│ @angular/compiler-cli     │ 22.3.0            │ ^22.3.0           │
│ @angular/core             │ 22.3.0            │ ^22.3.0           │
│ @angular/forms            │ 22.3.0            │ ^22.3.0           │
│ @angular/platform-browser │ 22.3.0            │ ^22.3.0           │
│ @angular/router           │ 22.3.0            │ ^22.3.0           │
│ ng-packagr                │ 22.3.0            │ ^22.3.0           │
│ rxjs                      │ 7.8.2             │ ~7.8.0            │
│ typescript                │ 6.0.3             │ ~6.0.2            │
│ vitest                    │ 5.1.2             │ ^5.0.0            │
└───────────────────────────┴───────────────────┴───────────────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions