Aurelia Typescript errors and how to get Visual Studio 2015 to build a asp.net core app
Aurelia 1.0 was recently released so I wanted to finally test it out.
I tried creating an Aurelia project using the Aurelia CLI (v. 0.17.0) within a Visual Studio 2015 asp.net core application. I followed the instructions but saw a lot of red squigly lines in the typescript files and the solution couldn’t build because of all the Typescript “module not found” errors.
I tried the Aurelia CLI with Visual Studio Code and the CLI command worked fine to build the site and start the built-in webserver. Later on I realized that some files also had Typescript “module not found” errors, like build.ts in aurelia_project\tasks folder couldn’t find modules “gulp” and “aurelia-cli”.
I tried to get the Typescript Webpack skeleton to work inside a asp.net core project. I saw the Typescript errors but I noticed a different error in system.d.ts about not being able to define System in a global scope or something. I opened the project within Visual Studio Code and I didn't get that error so I knew something was wrong in my Visual Studio 2015 setup.
After researching online and looking at all the configuration files in the projects (I'm new to Typescript and module loading) I figured out what the problem is and how to get everything working in Visual Studio 2015.
1st problem: Visual Studio 2015 was using Typescript 1.8.6 but Aurelia was using 2.0.0.
The Typescript Webpack Skeleton and the CLI both created a settings.json file in a .vscode directory with "typescript.tsdk": "node_modules/typescript/lib". After looking that setting up I found Visual Studio Code uses it to point to the Typescript compiler. And the version in node_modules as specified by package.json was 2.0.0.
I realized Visual Studio probably isn't using the 2.0.0 beta version of Typescript. Finally I found out how to update it. You have to download it from here: (https://www.microsoft.com/en-us/download/details.aspx?id=48593). It's hidden within the "Details" section. After downloading and installing it I verified it was installed by going to Help->About Microsoft Visual Studio. And the error in system.d.ts in the Webpack skeleton went away!
2nd problem: Typescript typings are missing
Because I was getting "module not found" errors in Visual Studio Code and 2015 I figured something was wrong with my projects themselves and not the editors. The errors prevented Visual Studio 2015 from compiling so I first looked up how to disable Typescript compiling because I would do it using the CLI or Webpack anyway. Finally found this: http://rostacik.net/2015/08/14/how-to-disable-building-of-typescript-files-in-visual-studio-2015/ and added the line to my project .xproj. Reloaded the project and built the solution and it worked!
After reading https://www.typescriptlang.org/docs/handbook/modules.html and https://www.typescriptlang.org/docs/handbook/module-resolution.html I realized I was getting the "module not found" Typescript errors because some "modules" didn't have Typescript definition files. For example, aurelia-framework in npm_modules has one but aurelia-cli doesn't. gulp also doesn't have one.
I installed the gulp typings file by using Typings (https://github.com/typings/typings) and the gulp "module not found" errors went away (after closing and reopening the file that had the error). aurelia-cli doesn't have any Typescript definition files so any file that tries to import it will show an error. Good thing is these are Typescript errors, not es5 errors. aurelia-cli and others are designed to work with AMD module loading system so you shouldn't get any errors when you build using the CLI or Webpack.
Note for Visual Studio 2015 ASP.NET Code projects
You need to add app.UseFileServer(); to Startup.cs so your app will serve static and default files. Otherwise when IIS Express (or IIS) runs your aurelia app will not get served up because index.html will not get served.
Hope that helps!









