-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
With Blazor .NET 8, using JSHost.ImportAsync in component in a Razor Class Library (RCL) to load a collocated JavaScript module doesn't appear to work #55817
Comments
For reference, there is a workaround but it means not using collocation of JavaScript. If you copy the JavaScript file to the 'wwwroot' folder in the RCL (I also renamed it to 'Test.js'), then change the JSHost.ImportAsync line to this:-
then it loads the module fine and all works great, its just the collocated JavaScript loading method that doesn't appear to work (unless of course I'm missing something obvious ;-) |
@aventius-software thanks for contacting us. This appears to relate to the native webassembly interop mechanism, not related to blazor. Collocating JS files only works for files with |
I don't think we have enough of context in cc @pavelsavara |
Blazor could add their own API for resolving location of the script and wrap Note that |
Hi @javiercn I was using the
Hi @pavelsavara I did try changing the path to start '../' (see examples at top of page), but that doesn't work either unfortunately. |
It (coincidentally) works because all |
We can of course just use the alternate method of placing the file in the wwwroot folder as I mentioned previously... maybe this isn't a true bug, but rather a current limitation then? Maybe this might be worth mentioning as a limitation in the documentation? |
I have opened a request for making the documention more clear dotnet/AspNetCore.Docs#32618 on this subject. We don't have a context of razor files on runtime level and supporting web files next to general purpose C# files doesn't make a lot of sense. I'm going to move the issue back to aspnetcore in case Blazor would want to add an API for path resolution or something like that. |
@maraf thanks for the details. This seems to be working as expected. We don't have plans to change the way the JS files get placed on the RCL nor to provide a special API to avoid specifying the |
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes. See our Issue Management Policies for more information. |
Is there an existing issue for this?
Describe the bug
Since the unmarshalled method of calling JavaScript from Blazor has been deprecated I'm trying to use the new JSImport attribute introduced with .NET 7 (although my project is .NET 8) and of course JSHost.ImportAsync to load a collocated JavaScript module, however I cannot get the module to load. The component and the JavaScript file are in a Razor component library (RCL) which I'm referencing in my Blazor webassembly project. I've followed the steps here with some slight modification and this works when the component and JavaScript are in the webassembly project, but if I move them to the RCL then I get an error in the console as show below:-
Unhandled exception rendering component: TypeError: Failed to fetch dynamically imported module: https://localhost:7293/_framework/Test.razor.js
Using normal JS interop from a RCL works fine, it seems that only the JSHost.ImportAsync method doesn't work when called in a RCL
Expected Behavior
After moving the component and code to the RCL, it should work the same as when the component and JavaScript code are in the webassembly project
Steps To Reproduce
so that contents now looks like this...
Exceptions (if any)
No response
.NET Version
8.0.205
Anything else?
The text was updated successfully, but these errors were encountered: