Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 - Import barrels cause 404 at runtime

I am trying to implement the import barrels structure that is described in this link (you may have to scroll down a bit) :

https://angular.io/docs/ts/latest/guide/style-guide.html#!#application-structure

The problem I am facing is that the index.ts files that I am creating and referencing like

import {...} from './shared/services';

are not found at runtime and are throwing 404s. If I reference the modules like

import {...} from './shared/services/index';

It works fine. The problem only appears at runtime, typescript does not complain and compiles successfully. I have duplicated the issue in a plunker:

https://plnkr.co/edit/ClE76zuihFTETLDGehnd?p=preview

You can see the error in the console.

Thanks in advance for your help!

like image 566
miket969 Avatar asked May 12 '16 10:05

miket969


1 Answers

I finally found something: https://www.reddit.com/r/Angular2/comments/4i2d9x/support_problem_with_barrels/

It seems, that this is not easily possible with SystemJS, because it can not handle barrel-files.

To solve this, you can add every file as you did with [...]/index or you can add them as a package in SystemJS

like image 54
Dinistro Avatar answered Sep 21 '22 21:09

Dinistro