Skip to content
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

CSB Javascript Not Found #24

Closed
netclectic opened this issue Jul 26, 2019 · 11 comments
Closed

CSB Javascript Not Found #24

netclectic opened this issue Jul 26, 2019 · 11 comments

Comments

@netclectic
Copy link

After updating my CSB app to v2.0.6 for Preview 7 I started seeing an issue on startup...

Microsoft.JSInterop.JSException: Could not find 'LocalStorage' in 'window.Blazored'.

Adding the script tag to my index.html, re the instructions for SSB, resolved the issue.

@dinonovak
Copy link

I can confirm that upgrading to Blazor Preview7 requires manual add on script tag to function properly.

@chrissainty
Copy link
Member

@netclectic - Is this still the case with v2.0.7?
@dinonovak - Which version are you using and is that client-side Blazor or server-side?

@netclectic
Copy link
Author

The problem is resolved with v2.0.7.

Thanks!

@chrissainty
Copy link
Member

Great stuff. I’m going to go ahead and close the issue as things seem to be working as expected now.

@joshhubers
Copy link

I'm still receiving this issue in the browser and updated the _Host file to:

<script src="_content/Blazored.LocalStorage/blazored-localstorage.js"></script>

Running the the latest LocalStorage - 2.0.11

Running core preview8 in docker image - core/sdk:3.0.100-preview8-disco

I get a 404 for the js file in the browser.

Thanks!

@chrissainty
Copy link
Member

@joshhubers Have you tried a clean/re-build/clear of browser cache. I've had a lot of people have this issue and one of those sorts it out.

There are some issues with the new Razor Class Library right now. So it might be best to just manually copy the JS file from this repo into your solution.

@thild
Copy link
Contributor

thild commented Aug 16, 2019

I have a blazorwasm app but served by a webapi. In order to get Blazored.LocalStorage working I had to add this to Blazored.LocalStorage.csproj.

  <ItemGroup>
    <!-- .js/.css files will be referenced via <script>/<link> tags; other content files will just be included in the app's 'dist' directory without any tags referencing them -->
    <EmbeddedResource Include="wwwroot\**\*.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />
    <EmbeddedResource Include="wwwroot\**\*.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />
    <EmbeddedResource Include="wwwroot\**" Exclude="**\*.js;**\*.css" LogicalName="blazor:file:%(RecursiveDir)%(Filename)%(Extension)" />
  </ItemGroup>

This will copy all embedded resources to bin/Debug/netstandard2.0/dist/_content/Blazored.LocalStorage/* so Kestrel can serve.
Doing this the tag <script src="_content/Blazored.LocalStorage/blazored-localstorage.js"></script> is added automatically by Blazor in index.html.
This not affect BlazorClientSide sample app.

I create a pull request #29.

@chrissainty
Copy link
Member

@thild This code is now legacy and not the way class libraries need to work going forward. As of right now the situation is this. Both JS and CSS in Razor Class libraries gets included in host projects correctly at development time. If you're not seeing this then see my comment above explaining the steps to go through to get things working.

However, both for client-side Blazor and server-side Blazor there is an issue with publishing which stop static assets being included correctly, this is going to be fixed in Preview 9 (I hope!).

@thild
Copy link
Contributor

thild commented Aug 17, 2019

@chrissainty Thanks for clarification. Investigating further I found that is a known Blazor issue dotnet/aspnetcore#13122. The workaround mentioned there is run the project in development environment.
ASPNETCORE_ENVIRONMENT=Development dotnet run
or setup Properties/launchSettings.json

{
    "profiles": {
        "ServerProjectName": {
            "commandName": "Project",
            "launchBrowser": true,
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "applicationUrl": "http://localhost:5000/"
        }
    }
}

However, you might consider keeping the EmbeddedResource workaround in .cpsproj until the Blazor team resolves this issue, as this does not affect the new way of referencing static assets.

@chrissainty
Copy link
Member

I've now pushed a new version of the package which no longer needs a JavaScript file. This should completely remove the issue. Please give it a go and let me know if you have any issues.

@thild
Copy link
Contributor

thild commented Aug 20, 2019

I tried the new version. Removed reference to js and everything is working. Nice solution. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants