TypeScript barrels break build
See original GitHub issueType 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
Issue Analytics
- State:
- Created 6 years ago
- Reactions:21
- Comments:16 (5 by maintainers)
Top Results From Across the Web
Barrel Import Appears To Break Load Order - Stack Overflow
It seems that when I import from the barrels, the component and service definitions aren't loaded ahead of the unit test code.
Read more >TS: Adding barrels into typescript | by Suyeon Kang - Medium
A barrel is a way to rollup exports from several modules into a single convenient module. The barrel itself is a module file...
Read more >Refactoring Your React/Vue/Angular/Typescript App? The ...
There are 3 steps to creating a barrel in your Typescript application. ... “/common” to “/core/v1/common” would absolutely break this code.
Read more >Automatic barrels (index.ts files) for your entire code base
Hi I'm quite new to typescript, and I am quite confused about the '--isolatedModules' flag. Is that recommended for performance? And if so, ......
Read more >Using barrel exports to organize React components
A barrel enables us to consolidate, or roll up, exports from multiple files or modules into one single module. Barrels streamline imports, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub 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.