Why do I get “Cannot find module 'angular2/core'” Intellisense errors in Visual Studio 2015

I’m using Visual Studio 2015 Update 1 with TypeScript 1.8.5.

I have an ASP.NET MVC 4.6 Web Application that uses Angular2.

I set up my TypeScript compile options using the following settings:

 <PropertyGroup>
  <TypeScriptTarget>ES5</TypeScriptTarget>
  <TypeScriptJSXEmit>None</TypeScriptJSXEmit>
  <TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled>
  <TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
  <TypeScriptModuleKind>System</TypeScriptModuleKind>
  <TypeScriptModuleResolution>node</TypeScriptModuleResolution>
  <TypeScriptRemoveComments>False</TypeScriptRemoveComments>
  <TypeScriptOutFile />
  <TypeScriptOutDir />
  <TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
  <TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
  <TypeScriptSourceMap>True</TypeScriptSourceMap>
  <TypeScriptMapRoot />
  <TypeScriptSourceRoot />
  <TypeScriptExperimentalDecorators>True</TypeScriptExperimentalDecorators>
</PropertyGroup>

The ErrorList contains no build errors, but it does contain Intellisense errors, such as the following:

 Cannot find module 'angular2/core'

But Angular2 as well as all of my other dependencies are where they should be, under the node_modules folder.

So the TypeScript compiles successfully to JavaScript and the resulting JavaScript works at runtime, but I see Intellisense errors in the Visual Studio environment across most of my application’s TypeScript files.

Additionally, some of the components I rely, such as ag-grid-ng2, have proper TypeScript definition files under node_modules but Intellisense treats them as if they are not typed (in other words, typed as ‘any’)

Why?

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

The problem was fixed by the following:

  1. Change the <TypeScriptModuleKind> setting from System to CommonJs
  2. Reboot Visual Studio entirely

Don’t skip step 2. And no, unloading and reloading the project won’t help.

I’m not sure why the Intellisense errors don’t go away until Visual Studio is rebooted, but that was our fix.