Blazor 6 : "Microsoft.TypeScript.MSBuild" and a collocated JavaScript file with a .razor file cause a build error on the Ubuntu
See original GitHub issueDescribe the bug
On the Ubuntu Linux 20.04 LTS, for a Blazor WebAssembly project (.NET 6) with the following conditions, 2nd time or later of execution, dotnet build
command causes the build error “Two assets found targeting the same path with incompatible asset kinds”.
- The project references “Microsoft.TypeScript.MSBuild” NuGet package.
- The project contains .razor.js files that are collocated with .razor files.
- The project also contains .razor.ts files, and they are transpiled to the .razor.js files above.
Notice:
- I encountered this problem with the .NET SDK 6.0.x on Ubuntu Linux 20.04 LTS on WSL2 on my Windows 11 Pro 21H2 x64, and GitHub Actions of
ubuntu-latest
. - The build error never occurred on Windows OS. (I don’t know the case on a macOS because I could not try it on macOS.)
- The 1st execution of the
dotnet build
was completed successfully whether runs on Ubuntu or Windows. - It seems the error happens only when the transpiled .razor.js files already exist before the build has been started.
- If I do not use TypeScript for collocated JavaScript with Razor component, the build error never occurred even though I continue using TypeScript for located JavaScript under the “wwwroot” folder.
- At that time, I used “Microsoft.TypeScript.MSBuild” NuGet package version 4.6.2, but in my case, the build error seems to happen even another version of “Microsoft.TypeScript.MSBuild” NuGet package such as version 3.x.
To Reproduce
Requirements
- Use the minimal project below that can reproduce this problem.
- Prepare a Ubuntu Linux 20.04 LTS and install the .NET SDK 6.0.201 in it.
Steps to reproduce
- Open a terminal on the Ubuntu Linux 20.04 LTS.
- Change the current directory to where you extracted the “BlazorCollocateJsWithRazor-net-sdk-6.0.201.zip” file.
- Execute
dotnet build command
and confirm it will be a success. - Execute
dotnet build command
one more time, then you will see the build error.
Exceptions (if any)
The build error message is below:
/usr/share/dotnet/sdk/6.0.201/Sdks/Microsoft.NET.Sdk.Razor/targets/Microsoft.NET.Sdk.Razor.JSModules.targets(95,5): error : Two assets found targeting the same path with incompatible asset kinds: [/mnt/c/Projects/Blazor/Trials/BlazorCollocateJsWithRazor/BlazorCollocateJsWithRazor.csproj]
/usr/share/dotnet/sdk/6.0.201/Sdks/Microsoft.NET.Sdk.Razor/targets/Microsoft.NET.Sdk.Razor.JSModules.targets(95,5): error : '/mnt/c/Projects/Blazor/Trials/BlazorCollocateJsWithRazor/App.razor.js' with kind 'All' [/mnt/c/Projects/Blazor/Trials/BlazorCollocateJsWithRazor/BlazorCollocateJsWithRazor.csproj]
/usr/share/dotnet/sdk/6.0.201/Sdks/Microsoft.NET.Sdk.Razor/targets/Microsoft.NET.Sdk.Razor.JSModules.targets(95,5): error : '/mnt/c/Projects/Blazor/Trials/BlazorCollocateJsWithRazor/App.razor.js' with kind 'All' [/mnt/c/Projects/Blazor/Trials/BlazorCollocateJsWithRazor/BlazorCollocateJsWithRazor.csproj]
/usr/share/dotnet/sdk/6.0.201/Sdks/Microsoft.NET.Sdk.Razor/targets/Microsoft.NET.Sdk.Razor.JSModules.targets(95,5): error : for path 'App.razor.js' [/mnt/c/Projects/Blazor/Trials/BlazorCollocateJsWithRazor/BlazorCollocateJsWithRazor.csproj]
Further technical details
dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.201
Commit: ef40e6aa06
Runtime Environment:
OS Name: ubuntu
OS Version: 20.04
OS Platform: Linux
RID: ubuntu.20.04-x64
Base Path: /usr/share/dotnet/sdk/6.0.201/
Host (useful for support):
Version: 6.0.3
Commit: c24d9a9c91
.NET SDKs installed:
5.0.406 [/usr/share/dotnet/sdk]
6.0.201 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.15 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.15 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Error BLAZOR106 when saving Javascript/TypeScript file ...
I was getting the same error but in my case I wasn't even using a razor component, just a razor page .cshtml file....
Read more >ASP.NET Core Blazor JavaScript interoperability (JS interop)
Collocation of JavaScript (JS) files for pages, views, and Razor components is a convenient way to organize scripts in an app.
Read more >JS interop with collocated files : r/Blazor
So I would like to add some JS functions to a specific component (let's say Index.razor) using a collocated file (Index.razor.js). How should...
Read more >Documentation - Compiler Options in MSBuild
Which compiler options are available in MSBuild projects. ... Generate .d.ts files from TypeScript and JavaScript files in your project.
Read more >Getting Started with TypeScript for JSInterop in Blazor
We now have our TypeScript file so how can we get it to build with our project. The first thing we need to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Filed an issue on TypeScript to track this problem here
Thanks for contacting us. This seems to be caused by the fact that you’re copying assets to the
wwwroot
folder. This blogpost should help you with resolving this issue: https://devblogs.microsoft.com/dotnet/build-client-web-assets-for-your-razor-class-library/We plan to productize the feature referenced in the blog post and make it part of the framework in .NET 7: https://github.com/dotnet/aspnetcore/issues/40572