question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript barrels break build

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

12reactions
dhergescommented, Oct 23, 2017

Here are issues that are related:

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

4reactions
jefforacommented, Mar 19, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found