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

Could not find 'BlazorExtensions' in 'window' (Server mode) #35

Open
cpsaez opened this issue Aug 13, 2019 · 17 comments
Open

Could not find 'BlazorExtensions' in 'window' (Server mode) #35

cpsaez opened this issue Aug 13, 2019 · 17 comments

Comments

@cpsaez
Copy link

cpsaez commented Aug 13, 2019

In a new project, using server side template, I added the reference to BlazorExtensions storage (0.2.1), added the services.AddStorage() line to register the services. If I modify the counter example to this:

`@page "/counter"
@using Blazor.Extensions.Storage
@Inject SessionStorage sessionStorage
@Inject LocalStorage localStorage

Counter

Current count: @currentCount

<button class="btn btn-primary" @OnClick="IncrementCount">Click me

@code {
int currentCount = 0;

async void IncrementCount()
{
    currentCount=await localStorage.GetItem<int>("counter");
    currentCount++;
    localStorage.SetItem("counter", currentCount).Wait();
}

}
`
I receive the error Could not find 'BlazorExtensions' in 'window'.
blazor.server.js is present in Sources when I enter in dev mode in chrome.
dotnet --version outputs 3.0.100-preview7-012821.

Is that correct?

@cpsaez
Copy link
Author

cpsaez commented Aug 13, 2019

If i compile the .ts scripts, put in wwwroot and init the script directly in _host.cshtml it works, so I think is related to #24

@seanmorangsp
Copy link

Same issue here. I'm on preview 8.

blazor.server.js:15 [2019-08-23T13:47:37.052Z] Error: Microsoft.JSInterop.JSException: Could not find 'BlazorExtensions' in 'window'.
Error: Could not find 'BlazorExtensions' in 'window'.
at https://localhost:5001/_framework/blazor.server.js:8:27768
at Array.forEach ()
at d (https://localhost:5001/_framework/blazor.server.js:8:27729)
at https://localhost:5001/_framework/blazor.server.js:8:28342
at new Promise ()
at e.beginInvokeJSFromDotNet (https://localhost:5001/_framework/blazor.server.js:8:28316)
at https://localhost:5001/_framework/blazor.server.js:1:19148
at Array.forEach ()
at e.invokeClientMethod (https://localhost:5001/_framework/blazor.server.js:1:19119)
at e.processIncomingData (https://localhost:5001/_framework/blazor.server.js:1:17165)
at Microsoft.JSInterop.JSRuntimeBase.InvokeWithDefaultCancellation[T](String identifier, IEnumerable`1 args)
at GSP.CampaignManagement.PageModels.LegacyPathModel.HandleValidSubmit() in C:\Dev\Tetris.UI\GSP.CampaignManagement.Web.SPA\GSP.CampaignManagement.Web.SPA\PageModels\LegacyPathModel.cs:line 46
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.Forms.EditForm.HandleSubmitAsync()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.Rendering.Renderer.GetErrorHandledTask(Task taskToHandle)

@dtitovgis
Copy link

Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: Could not find 'BlazorExtensions' in 'window'.
Error: Could not find 'BlazorExtensions' in 'window'.
at http://localhost:55460/_framework/blazor.server.js:8:28065
at Array.forEach ()
at p (http://localhost:55460/_framework/blazor.server.js:8:28026)
at http://localhost:55460/_framework/blazor.server.js:8:28733
at new Promise ()
at e.beginInvokeJSFromDotNet (http://localhost:55460/_framework/blazor.server.js:8:28707)
at http://localhost:55460/_framework/blazor.server.js:1:19148
at Array.forEach ()
at e.invokeClientMethod (http://localhost:55460/_framework/blazor.server.js:1:19119)
at e.processIncomingData (http://localhost:55460/_framework/blazor.server.js:1:17165)

Microsoft.JSInterop.JSException: Could not find 'BlazorExtensions' in 'window'.
Error: Could not find 'BlazorExtensions' in 'window'.
at http://localhost:55460/_framework/blazor.server.js:8:28065
at Array.forEach ()
at p (http://localhost:55460/_framework/blazor.server.js:8:28026)
at http://localhost:55460/_framework/blazor.server.js:8:28733
at new Promise ()
at e.beginInvokeJSFromDotNet (http://localhost:55460/_framework/blazor.server.js:8:28707)
at http://localhost:55460/_framework/blazor.server.js:1:19148
at Array.forEach ()
at e.invokeClientMethod (http://localhost:55460/_framework/blazor.server.js:1:19119)
at e.processIncomingData (http://localhost:55460/_framework/blazor.server.js:1:17165)
at Microsoft.JSInterop.JSRuntime.InvokeWithDefaultCancellation[T](String identifier, Object[] args)
at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args)
at Specification.Pages.Project.List.OnInitializedAsync() in D:\Projects\Specification\Specification\Specification\Pages\Project\List.razor:line 243
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'qQJbIZIECp3TFa7-c74qeBUNnv3yFNxH5U7lnDn-nuI'.

Microsoft.JSInterop.JSException: Could not find 'BlazorExtensions' in 'window'.
Error: Could not find 'BlazorExtensions' in 'window'.
at http://localhost:55460/_framework/blazor.server.js:8:28065
at Array.forEach ()
at p (http://localhost:55460/_framework/blazor.server.js:8:28026)
at http://localhost:55460/_framework/blazor.server.js:8:28733
at new Promise ()
at e.beginInvokeJSFromDotNet (http://localhost:55460/_framework/blazor.server.js:8:28707)
at http://localhost:55460/_framework/blazor.server.js:1:19148
at Array.forEach ()
at e.invokeClientMethod (http://localhost:55460/_framework/blazor.server.js:1:19119)
at e.processIncomingData (http://localhost:55460/_framework/blazor.server.js:1:17165)
at Microsoft.JSInterop.JSRuntime.InvokeWithDefaultCancellation[T](String identifier, Object[] args)
at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args)
at Specification.Pages.Project.List.OnInitializedAsync() in D:\Projects\Specification\Specification\Specification\Pages\Project\List.razor:line 243
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executed endpoint '/_blazor'
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 5343.0005ms 101

@galvesribeiro
Copy link
Member

Can you please try with the latest packages?

@Hinne123
Copy link

@galvesribeiro with the 1.1.0-preview1 it stays the same error message as dtitovgis posted before.

@rovercoder
Copy link

rovercoder commented Nov 14, 2019

Add this to your index.html or _Host.cshtml whichever you are using:

<script type="text/javascript" src="_content/Blazor.Extensions.Storage.JS"></script>

Should the blazor.extensions.storage.js file not get automatically generated clone this github repo and build the solution. You should then find the compiled js there inside the dist folder, then just copy it over to your project in /bin/Debug/netstandardx.x/dist/_content/

@arivera12
Copy link

arivera12 commented Dec 16, 2019

I downloaded the files and tried to compile them and a error is being thrown.
[typescript] Element implicitly has an 'any' type because type 'Window' has no index signature.

@arivera12
Copy link

Does someone compiled this successfully?

@rovercoder
Copy link

rovercoder commented Dec 16, 2019

Compiled JS for 1.1.0-preview3: blazor.extensions.storage.js.zip

@arivera12
Copy link

@rovercoder everything it's working again! Is this gonna get fixed later?

@rovercoder
Copy link

hope so!

@danielmeza
Copy link

I had the same problen with the SignalR package using the 3.1.0-preview4.19579.2 of Blazor and the 1.1.0-preview3 of SIgnalR

@bobted
Copy link

bobted commented Jan 27, 2020

I've tried using the js file that @rovercoder linked but it didn't help so I've been looking for other discussions about this problem. It looks like BlazorExtensions/SignalR#66 matches and also includes a fork with a potential workaround. The workaround includes adding app.UseStaticFiles(); to a server project's Startup.cs. I have not tried it yet but the thread makes it sound like it works.

@ar-iqbal
Copy link

add below lines in head section of _Host.cshtml

<script src="_content/MatBlazor/dist/matBlazor.js"></script>

@willoftw
Copy link

Disable your adblocker (Adblocker plus), had this exact issue on chrome, whitelisted localhost, problem solved

@seanmorangsp
Copy link

seanmorangsp commented Aug 24, 2020 via email

@malibayram
Copy link

An exception of type 'Microsoft.JSInterop.JSException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'Could not find 'BlazorExtensions.Storage.SetItem' ('BlazorExtensions' was undefined).
Error: Could not find 'BlazorExtensions.Storage.SetItem' ('BlazorExtensions' was undefined).
    at https://localhost:5011/_framework/blazor.server.js:1:67398
    at Array.forEach (<anonymous>)
    at e.findFunction (https://localhost:5011/_framework/blazor.server.js:1:67358)
    at b (https://localhost:5011/_framework/blazor.server.js:1:69100)
    at https://localhost:5011/_framework/blazor.server.js:1:70046
    at new Promise (<anonymous>)
    at e.beginInvokeJSFromDotNet (https://localhost:5011/_framework/blazor.server.js:1:70019)
    at https://localhost:5011/_framework/blazor.server.js:1:26303
    at Array.forEach (<anonymous>)
    at e.invokeClientMethod (https://localhost:5011/_framework/blazor.server.js:1:26273)'
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__15`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
   at Microsoft.JSInterop.JSRuntimeExtensions.<InvokeVoidAsync>d__0.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ValueTaskAwaiter.GetResult()

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