Skip to content

Import path for declarations is incorrectly transformed #52324

@tanishqmanuja

Description

@tanishqmanuja

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

compiler

Is this a regression?

No idea

Description

For the input file:

// file: projects\ngx-material\src\lib\ui\fab\fab.component.ts
import "@material/web/fab/fab";

import {
  ChangeDetectorRef,
  Component,
  ElementRef,
  NgZone,
  inject,
} from "@angular/core";
import type { FabSize, FabVariant, MdFab } from "@material/web/fab/fab";
import { coerceBooleanProperty } from "../../utils/coercion";
import { ProxyCmp } from "../../utils/proxy-cmp";

@ProxyCmp({ inputs: ["variant", "size", "label", "lowered"] })
@Component({
  standalone: true,
  selector: "md-fab",
  template: ` <ng-content></ng-content>`,
  inputs: [
    { name: "size", transform: (v: FabSize) => v },
    { name: "variant", transform: (v: FabVariant) => v },
    { name: "label", transform: (v: string) => v },
    { name: "lowered", transform: coerceBooleanProperty },
  ],
})
export class MdFabComponent {
  protected el: MdFab = inject(ElementRef).nativeElement;
  protected ngZone = inject(NgZone);
  private cdRef = inject(ChangeDetectorRef);

  constructor() {
    this.cdRef.detach();
  }
}

Is compiled to this,

// file: dist\ngx-material\lib\ui\fab\fab.component.d.ts

import "@material/web/fab/fab";
import { NgZone } from "@angular/core";
import { MdFab } from "@material/web/fab/fab";
import * as i0 from "@angular/core";
import * as i1 from "../../../../../../node_modules/.pnpm/@material+web@1.0.0/node_modules/@material/web/fab/internal/shared";
import * as i2 from "../../../../../../node_modules/.pnpm/@material+web@1.0.0/node_modules/@material/web/fab/internal/fab";
export declare class MdFabComponent {
    protected el: MdFab;
    protected ngZone: NgZone;
    private cdRef;
    constructor();
    static ɵfac: i0.ɵɵFactoryDeclaration<MdFabComponent, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<MdFabComponent, "md-fab", never, { "size": { "alias": "size"; "required": false; }; "variant": { "alias": "variant"; "required": false; }; "label": { "alias": "label"; "required": false; }; "lowered": { "alias": "lowered"; "required": false; }; }, {}, never, ["*"], true, never>;
    static ngAcceptInputType_size: i1.FabSize;
    static ngAcceptInputType_variant: i2.FabVariant;
    static ngAcceptInputType_label: string;
    static ngAcceptInputType_lowered: any;
}

Import i1 and i2 paths are changed to relative paths, which results in errors while consuming the lib.

Please provide a link to a minimal reproduction of the bug

https://github.com/tanishqmanuja/issue.ngx-material

Please provide the exception or error you saw

While consuming the lib

❯ ng serve
X [ERROR] TS2307: Cannot find module '../../../../../../node_modules/.pnpm/@material+web@1.0.0/node_modules/@material/web/fab/internal/shared' or its corresponding type declarations. [plugin angular-compiler]

    dist/md3/lib/ui/fab/fab.component.d.ts:5:20:
      5 │ ...as i1 from "../../../../../../node_modules/.pnpm/@material+web@1...
        ╵               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


X [ERROR] TS2307: Cannot find module '../../../../../../node_modules/.pnpm/@material+web@1.0.0/node_modules/@material/web/fab/internal/fab' or its corresponding type declarations. [plugin angular-compiler]

    dist/md3/lib/ui/fab/fab.component.d.ts:6:20:
      6 │ ...as i2 from "../../../../../../node_modules/.pnpm/@material+web@1...
        ╵               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Angular CLI: 17.0.0-rc.0
Node: 20.7.0 (Unsupported)
Package Manager: pnpm 8.8.0
OS: win32 x64

Angular: 17.0.0-rc.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router       

Package                         Version
---------------------------------------------------------    
@angular-devkit/architect       0.1700.0-rc.0
@angular-devkit/build-angular   17.0.0-rc.0
@angular-devkit/core            17.0.0-rc.0
@angular-devkit/schematics      17.0.0-rc.0
@schematics/angular             17.0.0-rc.0
ng-packagr                      17.0.0-next.2
rxjs                            7.8.1
typescript                      5.2.2
zone.js

Anything else?

No response

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: compilerIssues related to `ngc`, Angular's template compilerstate: has PR

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions