5

I am trying to create an Angular 2 application using Typescript in Visual Studio 2015. I have installed npm on my machine. When I compile my application , I am getting errors cannot find module '@angular/core'. It is referred in all the ts files under the node_modules folder in the import statement. For e.g.

import { ElementRef, AfterViewInit, OnDestroy, DoCheck, EventEmitter, IterableDiffers } from '@angular/core';

I am currently getting around 500 plus errors. The error goes off when I replace it with 'angular2/core '. Also just to let you know , I am using PrimeNG UI Components in my project as well.

Could somebody help ? I don't understand why it is looking at @angular/core ?

3
  • I suggest using cli.angular.io . See also youtube.com/watch?v=wHZe6gGI5RY Commented May 13, 2016 at 14:49
  • Thanks. Can I include the code structure generated by cli.angular.io into my visual studio solution Commented May 13, 2016 at 15:14
  • Sorry, can't help you with that. Commented May 13, 2016 at 15:20

4 Answers 4

5
  1. Install nodejs
  2. Open cmd prompt and type 'cd your project directory'
  3. Type 'npm install' and hit enter.

This will create a node_modules folder within that directory which should have the @angular/core that's required.

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

Comments

2

The angular2 name in modules names is for versions before RC (release candidate) versions (beta ones) and the @angular one for RC versions.

5 Comments

I am using angular2 2.0.0-beta.17 version. So then what is the problem
So you need to use: import { ... } from 'angular2/core';
I am bit confused now. When I execute npm install angular2, it installs ngular2 2.0.0-beta.17 version. How do I install the release candidate version. As I need to use the latest.
In fact there are several packages to install for rc versions: @angular/core, ...
see this link for more details: angular.io/docs/ts/latest/quickstart.html
2

You first need to add typings at global level as below.

npm install -g typings

Then create typings.json using below command.

typings init

Paste below code in typings.json

{
  "name": "ng2-application",
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160725163759",
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
    "node": "registry:dt/node#6.0.0+20160909174046"
  }
}

Now you need to add below code in tsconfig.json

 "compilerOptions": {
        "moduleResolution": "node"
       }

After doing above steps you will able to get definitions on F12.

Comments

0

When I had this issue, it would come and go depending on the module kind I had selected. (Visual Studio, right-click project, properties, Typescript tab. It would occur for the "System" Module System, which is used in Angular2 QuickStart tutorial, but not for some others, for example.)

I verified the folder /node_modules/@angular/core/ existed in the proj and was populated.

Solution was to edit the .csproj file and add the line <TypeScriptModuleResolution>Node</TypeScriptModuleResolution> in both Debug and Release sections. VS defaults to Classic for this setting for some settings of ModuleKind.

Comments

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.