Chrome showing blank TypeScript file
Asked Answered
C

6

18

I am setting up a new TypeScript project in visual studio 2013.

I have the option on my VS project to generate source maps checked. I have the option to specify root directory for typescript files and specify root directory for sourcemap files unchecked.

I have the option in Chrome Dev tools to enable JS sourcemaps checked.

At the bottom of my generated app.js file I see:

//# sourceMappingURL=app.js.map

And that file exists.

I do not see the source maps being downloaded in the network pane, and when I open the .ts file in the sources pane, I just see a blank file.

Any ideas? Thanks!

Chapiter answered 23/7, 2015 at 15:31 Comment(1)
Try deleting the .js and .js.map files and regenerate the javascript code again and try to run again. Sometimes the map files get corrupted.Dineric
W
19

Place this in your web.config to serve up the TS files:

<configuration>
    ...
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".ts" mimeType="application/x-typescript" />
        </staticContent>
    </system.webServer>
</configuration>
Waggish answered 30/7, 2015 at 15:21 Comment(0)
J
6

Cordle's answer worked for me, but I also needed to remove the existing MIME map for .ts.

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

The default MIME map for .ts files was "video/vnd.dlna.mpeg-tts".

Journeywork answered 16/12, 2015 at 12:21 Comment(1)
this was perfect. thanks for the details on default ts mappingSowers
C
3

I figured out what was going on. I needed to add a mime map for the extension .ts either in IIS or in my web.config. So the browser was asking for the TypeScript file but not getting anything back, therefore it showed up blank.

Chapiter answered 28/7, 2015 at 13:26 Comment(1)
This explained why it worked for me in Chrome "out of the box" whilst another developer had to add the mimeMap to our web.config file. I already had a ".ts" mime type entry in IIS but the other developer didn't.Dogvane
M
0

I had a similar issue, finally figured out that I had listed a SourceUrl

//# sourceURL=CommonLib.js

at the bottom of my Ts Script, which caused the folder of the Map and Ts file to be different.

Mckenna answered 12/4, 2016 at 10:40 Comment(0)
H
0

Add MIME to web.config: OR IIS.

Helbona answered 30/9, 2017 at 8:37 Comment(0)
M
0

If it works on localhost but shows blank after publishing to any environment it is probably due to that the .ts-files are not included.

To include .ts-files on Debug publish add this at the bottom of the web .csproj where the other <Target Name are. If you wan't .ts-files on every publish remove Condition="'$(Configuration)'=='Debug'".

<Target Name="AddTsToContent" AfterTargets="CompileTypeScript" Condition="'$(BuildingProject)' != 'false'">
   <ItemGroup>
      <Content Include="@(TypeScriptCompile)" Condition="'$(Configuration)'=='Debug'"/>
   </ItemGroup>
</Target>

Source: How to include TypeScript files when publishing?

Mercurialize answered 1/2, 2019 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.