Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript: TSX files show up blank in Chrome

When attempting to debug a TypeScript application in Google Chrome, the *.ts files are source mapped properly in the inspectors, but the *.tsx files appear totally empty, which doesn't really help me debug them.

How can I get *.tsx files to source map correctly?

like image 459
thedayturns Avatar asked Oct 12 '15 20:10

thedayturns


People also ask

How do I open a TSX file?

How to open a TSX file. Because TSX files are plain text files, you can open them in any text editor. However, TSX files are meant to be opened and edited in source code editors, such as Microsoft Visual Studio (Windows) or Github Atom (cross-platform).


Video Answer


2 Answers

I would suggest you to try add MIME type for *.tsx files for used web server.

In case your project is hosted on IIS try to add this to your web.config:

<system.webServer>
  ...
  <staticContent>
    <remove fileExtension=".tsx" />
    <mimeMap fileExtension=".tsx" mimeType="application/javascript" />
  </staticContent>
</system.webServer>
like image 149
ahz Avatar answered Oct 18 '22 19:10

ahz


I was unable to make the web.config based solution work in my .NET Core app. So, I used IApplicationBuilder.UseStaticFiles. Since the purpose is just to use TypeScript source maps for development, I made it only serve the files when the app is in development mode.

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseStaticFiles();

    if (env.IsDevelopment())
    {
        var options = new StaticFileOptions
        {
            // Replace "Scripts" with the path to your TypeScript folder
            // (this is also a workaround for the fact that we don't keep TypeScript files under wwwroot)
            FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "Scripts")),
            RequestPath = new Microsoft.AspNetCore.Http.PathString("/Scripts"),
            ServeUnknownFileTypes = true
        };
        app.UseStaticFiles(options);
    }
}
like image 2
Rikki Gibson Avatar answered Oct 18 '22 18:10

Rikki Gibson