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
- refactor(): correct folder structure issues on lib modules * Simplified the inner folder structure * Remove inner modules in extensions lib * Expose nested modules by directly pointing instead of usi... — committed to ngx-extensions/ngx-extensions by deleted user 6 years ago
- refactor(): correct folder structure issues on lib modules * Simplified the inner folder structure * Remove inner modules in extensions lib * Expose nested modules by directly pointing instead of usi... — committed to ngx-extensions/ngx-extensions by deleted user 6 years ago
- fix(angular): generate metadata for supporting aot builds - https://github.com/ng-packagr/ng-packagr/issues/195 - required to import/export from an explicit file — committed to brspence/momentum-ui by deleted user 5 years ago
- fix(angular): generate metadata for supporting aot builds - https://github.com/ng-packagr/ng-packagr/issues/195 - required to import/export from an explicit file — committed to momentum-design/momentum-ui by deleted user 5 years ago
- Workaround https://github.com/ng-packagr/ng-packagr/issues/195 — committed to adia-technology/policies-consent-widget by deleted user 4 years ago
- Merge pull request #24 from adia-technology/Fix_prod_build_problems Workaround https://github.com/ng-packagr/ng-packagr/issues/195 — committed to adia-technology/policies-consent-widget by PiotrSzperka 4 years ago
- fix(angular): generate metadata for supporting aot builds - https://github.com/ng-packagr/ng-packagr/issues/195 - required to import/export from an explicit file — committed to momentum-design/momentum-angular by deleted user 5 years ago
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…
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/indexnotation, the metadata is correctly generated.So for me, appending
/indexis 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';