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?
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).
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>
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With