wonderful world
wonderful world

Reputation: 11599

Unable to run the Angular2 app in IIS

I followed the Angular2 Quick start example and used live-server to run it. It works fine.

I created then a web site in IIS and set the virtual directory to the directory where I have the index.html file. When I run the website I get the following error. The error happens when the IIS tries to server app.ts.

How can run the Angular2 app in IIS?

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

UPDATE:

Solution: I created a new web.config file and added the following snippet of code to add the MIME type. This will be used by the IIS as the local web app settings.

<configuration>
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".ts" mimeType="application/x-typescript" />
        </staticContent>
    </system.webServer>
</configuration>

enter image description here

Upvotes: 0

Views: 3224

Answers (2)

Juli&#235;n
Juli&#235;n

Reputation: 9562

By convention, it is not advised to directly serve TypeScript (.ts) files. This is why IIS doesn't enable this by default. The quickstart tutorial also explicitely mentions this halfway the page, on section What's wrong with this?, where it states the following:

We were up and running in a hurry and we could explore Angular in this manner for quite some time. For a number of reasons this isn't a good approach for building an application:

  • Transpiling TypeScript in the browser becomes tediously slow when our app grows beyond a few files. We certainly won't do that in production. We should learn to compile locally and push the generated JavaScript to the server. We'll need some tools for that.

So if you take a couple of minutes more and finish the tutorial, it'll work out for you just fine without having to bother with IIS configuration.

That being said, if you truly want it, it is possible. Like mentioned in other comments, you can add a MIME type for .ts files in IIS. In the SO question What's the MIME-Type of TypeScript it is explained as well.

Upvotes: 2

DanielS
DanielS

Reputation: 774

try to register a .ts mime type

Add a MIME Type (IIS 7)

Also, this SO seems like a good explanation

Upvotes: 1

Related Questions