0

Using Visual Studio 2015 and a asp.net core project and angular2 (rc1) with typescript.

I am having a major issue with Angular2 and the new paths @angular/core for instance.

the problem is that the typescript compiler cant find @angular directive. and i cant find any way to fix this. so question is how do i make the visual studio compiler understand where to look for the angular files. or is it not even possible to do so?

import {ROUTER_PROVIDERS} from '@angular/router'; // this gives error
import {HTTP_PROVIDERS} from '@angular/http';

import { AppComponent } from './app.component';  // this works


bootstrap(AppComponent, [ROUTER_PROVIDERS,  HTTP_PROVIDERS]);

error message is: Error TS2307 Build: Cannot find module '@angular/router'.

The application is working even with these compile errors. since the script files are included from the npmcdn.com repository.

1 Answer 1

1

By not having a file directory ./ etc, it is by default looking at the node_modules folder.

If you have these located elsewhere you need to point to that location.

import {ROUTER_PROVIDERS} from '../somewhere-else/@angular/router';

If you're trying to use a CDN (which I would highly advise against doing), you will still need to let SystemJS or Webpack know about your angular packages that are globally placed on the window.

A webpack example:

// webpack.config.js
module.exports = {
  externals: {
    '@angular/router': 'angular.router' // This right side might be different
  }
};

I would suggest using npm and containing your neccessary files within node_modules. This way, when you are doing things like importing specific parts of libraries, it will only grab those specific portions. A CDN will include the entire library, and pollute your global window namespace (which is just bad joo-joo)

Sign up to request clarification or add additional context in comments.

1 Comment

i am using npm, but keeps getting these problems i have also tried going back to beta17 and using angular2/... paths but dosent work either maybe something is wrong in my setup. CDN is used or the html page just so i dont have to host the files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.