BlazorExtensions / Storage

HTML5 Storage API implementation for Microsoft Blazor
MIT License
228 stars 35 forks source link

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

Open cpsaez opened 5 years ago

cpsaez commented 5 years ago

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 commented 5 years ago

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

seanmorangsp commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

Can you please try with the latest packages?

Hinne123 commented 4 years ago

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

rovercoder commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Does someone compiled this successfully?

rovercoder commented 4 years ago

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

arivera12 commented 4 years ago

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

rovercoder commented 4 years ago

hope so!

danielmeza commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

add below lines in head section of _Host.cshtml

willoftw commented 4 years ago

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

seanmorangsp commented 4 years ago

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 notifications@github.com Sent: Monday, August 24, 2020 4:50 AM To: BlazorExtensions/Storage Storage@noreply.github.com Cc: Sean Moran Sean.Moran@gspretail.com; Comment comment@noreply.github.com 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.

malibayram commented 3 years ago
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()