Storage icon indicating copy to clipboard operation
Storage copied to clipboard

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

Open cpsaez opened this issue 4 years ago • 17 comments

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 avatar Aug 13 '19 15:08 cpsaez

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 https://github.com/BlazorExtensions/Storage/issues/24

cpsaez avatar Aug 13 '19 16:08 cpsaez

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)

seanmorangsp avatar Aug 23 '19 13:08 seanmorangsp

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

dtitovgis avatar Oct 18 '19 08:10 dtitovgis

Can you please try with the latest packages?

galvesribeiro avatar Oct 30 '19 20:10 galvesribeiro

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

Hinne123 avatar Nov 12 '19 09:11 Hinne123

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/

rovercoder avatar Nov 14 '19 22:11 rovercoder

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 avatar Dec 16 '19 18:12 arivera12

Does someone compiled this successfully?

arivera12 avatar Dec 16 '19 18:12 arivera12

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

rovercoder avatar Dec 16 '19 18:12 rovercoder

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

arivera12 avatar Dec 16 '19 19:12 arivera12

hope so!

rovercoder avatar Dec 16 '19 19:12 rovercoder

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

danielmeza avatar Jan 13 '20 05:01 danielmeza

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.

bobted avatar Jan 27 '20 12:01 bobted

add below lines in head section of _Host.cshtml

ar-iqbal avatar Apr 25 '20 16:04 ar-iqbal

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

willoftw avatar Aug 24 '20 08:08 willoftw

I had a similar experience in IE11. Had to ensure I was using JS 5 not 6. Used Babel to convert and all worked well.

From: willoftw [email protected] Sent: Monday, August 24, 2020 4:50 AM To: BlazorExtensions/Storage [email protected] Cc: Sean Moran [email protected]; Comment [email protected] Subject: Re: [BlazorExtensions/Storage] Could not find 'BlazorExtensions' in 'window' (Server mode) (#35)

[External Email]

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/BlazorExtensions/Storage/issues/35#issuecomment-678997454, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMH6PASOLE7S7IEEGTQVJO3SCISVBANCNFSM4ILMGDLQ.

seanmorangsp avatar Aug 24 '20 14:08 seanmorangsp

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()

malibayram avatar Dec 15 '20 17:12 malibayram