Skip to content

(webpack) Cannot import with barrels #1585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
efriandika opened this issue Aug 7, 2016 · 8 comments
Closed

(webpack) Cannot import with barrels #1585

efriandika opened this issue Aug 7, 2016 · 8 comments

Comments

@efriandika
Copy link

efriandika commented Aug 7, 2016

Please look at this code:

import {NavbarComponent, FooterComponent} from './shared/index';

@Component({
    selector: 'app',
    templateUrl: 'app.component.html',
    directives: [NavbarComponent, FooterComponent]
})
export class AppComponent {}

It will get an error: EXCEPTION: Unexpected directive value 'undefined' on the View of component AppComponent'

When I dont use barrels:

import {NavbarComponent} from './shared/navbar/navbar.component';
import {FooterComponent} from './shared/footer/footer.component';

It run properly.

So, what should I do ? Is this a bugs of angular cli ?

Version: angular-cli@webpack
OS: MacOSX El Capitan

@hansl
Copy link
Contributor

hansl commented Aug 8, 2016

Could you give me the content of the index file for your shared directory? Thanks.

@coryrylan
Copy link
Contributor

coryrylan commented Aug 8, 2016

I have the same issue. I can try to come up with a reduced example as well. I noticed it wont allow imports form barrels if they are components. Services and pipes seem to work just fine.

This is what my shared/index.ts looks like

export * from './components/collapse-text';
export * from './components/geo-button'
export * from './components/google-static-map';
export * from './components/image-gallery';
export * from './components/loading-spinner';
export * from './components/social-sharing-links';
export * from './dto/org';
export * from './dto/postal-code';
export * from './pipes/ellipsis.pipe';
export * from './services/geo.service';
export * from './services/graph.service';
export * from './services/postal-code.service';
export * from './services/postal-code.service';
export * from './services/sale.service';
export * from './services/settings.service';
export * from './services/viewport.service';

@hansl
Copy link
Contributor

hansl commented Aug 8, 2016

Okay. I suggest as a temporary workaround to remove the barrels. With Angular RC5 the styleguide is moving away from barrels and we will as well.

Sorry for the temporary inconvenience.

@hansl hansl closed this as completed Aug 8, 2016
@hansl
Copy link
Contributor

hansl commented Aug 8, 2016

Sorry if I was missing some information. Barrels are being replaced with NgModules so where you have to specify directives for your components, you'll simply put them in your module and they'll be available to all components (in the same NgModule).

@efriandika
Copy link
Author

Thanks for the information @hansl

@layton-glympse
Copy link

@hansl so, just to be clear, this means that index.ts files are no longer the way to retrieve package contents?
Seems weird, because I can still get angular contents from their barrels...?

@ghost
Copy link

ghost commented Sep 11, 2016

@hansl how would this work with e.g. domain objects? They are not components/directives. Right now we've got a separate file per domain class, and exporting them all in index.ts.
I can't put them in an ngModule as they are not Angular objects. How should I be doing that?

@hansl
Copy link
Contributor

hansl commented Sep 18, 2016

You mean simple utility class? No one is preventing you from using a barrel, just that the CLI will not produce barrels anymore.

If you have a specific issue, please file a separate issue with examples so we move the conversation there. I consider this done and will lock the conversation.

@angular angular locked and limited conversation to collaborators Sep 18, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants