ng-packagr: TypeScript barrels break build

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

When trying to build a library of reusable Angular component, ng-packagr doesn’t seem to package the generated distribution version correctly

How To Reproduce

ng-package.json

{
  "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
  "dest": "package",
  "lib": {
    "entryFile": "src/lib/public_api.ts"
  }
}

src/lib/public_api.ts

export * from './modules/modules-a';
export * from './modules/modules-b';
export * from './modules/modules-c';

Then, in each module folder I have an index.ts to export the specific module:

src/lib/modules/module-a/index.ts

export * from './component-a.component';
export * from './component-a.module';

Expected Behaviour

When I generate the library with ng-packagr -p ng-package.json, the ngx-customer-library.metadata.json contains only this line of code:

{"__symbolic":"module","version":3,"exports":[{"from":"./modules/module-3/"}],"metadata":{},"origins":{},"importAs":"my-angular-library"}a

However, everything is working fine if inside my src/lib/public_api.ts I add an extra /index:

export * from './modules/modules-a/index';
export * from './modules/modules-b/index';
export * from './modules/modules-c/index';

Version Information

ng-packagr: v1.4.1
node: v8.6.0
@angular: v4.4.5
rxjs: 5.4.3
zone.js: .8.18
@angular/cli: 1.3.2

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 21
  • Comments: 16 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Here are issues that are related:

Seeing all this, I think it’s best to not use TypeScript barrels!

I’ve also opened a pull request angular/angular#22856 which fixes the issue in my specific reproduction above, so might cover quite a few of these issues.

I have created a minimal reproduction for this issue in a situation we were encountering it here: https://github.com/jeffora/ng-barrel.

Hopefully the README is easy enough to follow, but I’m assuming this isn’t actually a bug with ng-packagr, as the issue is the metadata.json is generated incorrectly with missing classes when using barrel files. cc @dherges

I’m having the same issue. The error message is rather ambiguous, adding it here for search ability as it took me a while to find this thread…

projects/mymodule/src/lib/reducers/index.ts(6,31): error TS2307: Cannot find module 'src/lib/reducers/myreducer.reducer'.
projects\mymodule\src\lib\mymodule.module.ts(15,39): Error during template compile of 'MyModule'
  Could not resolve src/lib/reducers relative to [object Object]..

Any update?

Hi, I’m building with Angular 6.1.8, and I still have this problem. When my ‘public_api.ts’ exports pure directories with barrel files, the generated metadata is empty. When exporting with folder/index notation, the metadata is correctly generated.

So for me, appending /index is still required.

@toupeira did you have to change any setting to make it work?

I was facing a similar issue and fixed it by pointing directly at the index file like so.

export * from './modules/modules-a/index';