10
votes

I'm trying to add Typescript to an existing .NET MVC project. I however get weird error-messages when I try to build. The Intellisense works and I can see that the typeings works. I can also see the .js-files being generated on manual save, meaning that the compileOnSave works. It's only when I try to build the whole project the errors show up.

enter image description here

I use the following settings in Visual Studio 2015:

  • Have installed typescript 2.0.3

  • Added the following devDependencies in my package.json-file

enter image description here

  • My tsconfig-file looks like this

enter image description here

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

enter image description here

6

6 Answers

1
votes

I had an app that showed the 'cannot find module' message in the editor when viewed in Visual Studio 2015 [TypeScript 2.0.6] - but worked perfectly in VSCode!

I tried all the recommended changes found on StackOverflow and on other sites but none of them worked for me. The change that fixed my problem was 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 somebody else.

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

0
votes

Are your npm dependencies installed? If not, then you should run npm install command on your project folder manually, or to avoid this in the future, you can automatically install npm packages to your project on build by editing your .njsproj file, after 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 it on rebuild, then:

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

The --msvs_version=2015command line option is not mandatory, but if you use multiple versions of VS or your npm is not set up correctly, then it might be useful.

0
votes

The solution posted here works for me: Cannot find module when compiling under Visual Studio

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

0
votes

I had the same issue and fixed by installing npm.

npm install

0
votes

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

  • Right Click Project in Solution Explorer, "Properties"
  • TypeScript Build (tab on left)
  • Change selection under Module system
0
votes

I had same problem with Visual Studio 2017. Solved problem installing angular-cli. Hope it can help :)