ng packagr auto-generated path issues

106 Views Asked by At

I'm working on creating stand-alone ng-libraries to be used in a parent app. Each of these libraries have multiple model files that are being used. But ng-packagr seems to be messing up the model file paths.

For example

import("projects/reports/src/lib/models/report.model").ReportModel[]

while the correct path should be the complete absolute path

export declare const selectState: import

import("../../../Users/Abhi/code/app/projects/reports/src/lib/models/report.model").ReportModel[]
2

There are 2 best solutions below

0
On

One workaround for this is to inline all the models wherever they are used in the code instead of importing them as files. This is not the best solution but it works. For eg.

export interface Report {
    fromDate: Date;
    toDate: Date;
}

@Component({....})
// rest of the code
0
On

It turns out that the issue is with Typescript v2.9.2. This get resolves after upgrading to v3+.

But keep in mind that Typescript v3 is only supported in Angular v7+.

Unless you don't want to upgrade to Angular v7, you can inline the models as shown in the other answer.