Code Grasshopper Code Grasshopper - 1 month ago 7
TypeScript Question

TS2307 Cannot find a module

I'm trying to learn Angular 2 using their quick start guide, tour of heroes and the style guide. But instead of following it to the letter I'm trying to adapt it to a little project of mine. This is probably a very dumb mistake but I'm a little uncomfortable with how Angular 2 manages imports and exports.

I'm getting the following error on

NPM start
.

enter image description here

I'm trying to import a User service and user model from the shared folder withing the User folder module, my structure looks like so:

enter image description here

And my code looks like this:

enter image description here

I know what the error means, it is right there after all; the module cannot be found but I have tried
.user/shared
,
../shared
and
/users/shared
but nothing works. I don't think it matters but each module has a shared folder, my code is based on this example: https://angular.io/docs/ts/latest/guide/style-guide.html#!#application-structure

app/heroes/heroes.component.ts


Any pointers to solve this would be awesome.

Edit: Modified as suggested with a index.ts under the shared folder. But now the app won't load properly.

enter image description here

Answer

Add an index.ts (barrel) file in the shared directory, that exports the files from the shared directory

index.ts

export * from './user.model';
export * from './mock-users';
export * from './user.service';