Visual Studio 2015 - Typescript "Build: Cannot Find Module ..."

I am trying to add Typescript to an existing .NET MVC project. However, I get weird error messages when I try to build. The work of Intellisense works, and I see that it works. I also see that .js files are generated when manually saved, which means that compileOnSave is working. This is only when I try to build an entire project, errors appear.

enter image description here

I use the following settings in Visual Studio 2015:

  • Installed Typescript 2.0.3

  • Added the following devDependencies in my package.json file

enter image description here

  • My tsconfig file is as follows

enter image description here

  • This is how I import the dependencies specified in the package.json file.

enter image description here

+9
visual-studio visual-studio-2015 typescript
source share
6 answers

Are your npm dependencies installed? If not, you should either run the npm install command in the project folder manually or avoid this in the future, you can automatically install npm packages in your project during assembly by editing your .njsproj file after the line

 <Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsTools.targets" /> 

add the following section:

 <PropertyGroup> <PreBuildEvent> npm install --msvs_version=2015 </PreBuildEvent> </PropertyGroup> 

Or, if you only want to restore it, then:

 <PropertyGroup> <BeforeRebuildEvent> npm install --msvs_version=2015 </BeforeRebuildEvent> </PropertyGroup> 

The command line --msvs_version=2015 is optional, but if you are using multiple versions of VS or your npm is not configured correctly, then this may be useful.

0
source share

The solution is posted here for me: Cannot find the module when compiling in Visual Studio

(Upgrade to the latest TypeScript version for Visual Studio 2015 here: https://www.microsoft.com/en-us/download/details.aspx?id=48593 )

0
source share

I had an application that displayed the message β€œI can’t find the module” in the editor when viewing in Visual Studio 2015 [TypeScript 2.0.6] - but it worked fine in VSCode!

I tried all the recommended changes found in StackOverflow and other sites, but none of them worked for me. The changes that fixed my problem were to remove the 'outDir' property from the tsconfig file! I know that the code in the original question does not use the outDir property, but this answer may help someone else.

This change was also necessary for VS2017. My suggestion: use VSCode if possible! :)

0
source share

I had the same problem and fixed npm installation.

npm install

0
source share

I am using RequireJS and I need to change the modular system from CommonJS to AMD. In Visual Studio:

  • Right-click the project in Solution Explorer, Properties
  • TypeScript Assembly (tab on the left)
  • Change selection in a modular system
0
source share

I had the same problem with Visual Studio 2017. The problem with installing angular-cli was fixed. Hope this helps :)

0
source share

All Articles