简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM