Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

window not defined #1238

Closed
Closed
@k11k2

Description

@k11k2

Willing to pass my Token from asp.net to angular

Index.cshtml

<script type="text/javascript">  
    window.appConfig = {
        Token: '@ViewData["token"]'
    }
</script>

<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>

<script src="~/dist/vendor.js" asp-append-version="true"></script>
@section scripts {
    <script src="~/dist/main-client.js" asp-append-version="true"></script>
}

Coming to app.module.shared.ts

import { APP_CONFIG } from './components/appConfig'

@NgModule({
declarations: [],
imports: [],
providers: [
        { provide: APP_CONFIG, useValue: window['appConfig'] }             
    ]
})

later in the components I'm going to use it as appConfig.Token is this scenario I face window not defined.

Error

An unhandled exception occurred while processing the request.
NodeInvocationException: Prerendering failed because of error: ReferenceError: window is not defined
at C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:19463:114
at Object.<anonymous> (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:19469:2)
at __webpack_require__ (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:20:30)
at Object.hasOwn (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:17482:77)
at __webpack_require__ (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:20:30)
at Object.<anonymous> (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:19763:81)
at __webpack_require__ (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:20:30)
at C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:66:18
at Object.<anonymous> (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:69:10)
at Module._compile (module.js:571:32)
Current directory is: C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore
Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance+<InvokeExportAsync>d__7.MoveNext()
Stack Query Cookies Headers 
NodeInvocationException: Prerendering failed because of error: ReferenceError: window is not defined at C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:19463:114 at Object.<anonymous> (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:19469:2) at __webpack_require__ (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:20:30) at Object.hasOwn (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:17482:77) at __webpack_require__ (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:20:30) at Object.<anonymous> (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:19763:81) at __webpack_require__ (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:20:30) at C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:66:18 at Object.<anonymous> (C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore\ClientApp\dist\main-server.js:69:10) at Module._compile (module.js:571:32) Current directory is: C:\Users\abhishikt.kandavalli\Documents\Visual Studio 2017\Projects\angularTemplateCore\angularTemplateCore 
Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance+<InvokeExportAsync>d__7.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance+<InvokeExportAsync>d__13.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNetCore.NodeServices.NodeServicesImpl+<InvokeExportWithPossibleRetryAsync>d__10.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.NodeServices.NodeServicesImpl+<InvokeExportWithPossibleRetryAsync>d__10.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNetCore.SpaServices.Prerendering.PrerenderTagHelper+<ProcessAsync>d__29.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner+<RunAsync>d__0.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
AspNetCore._Views_Callback_callback_cshtml+<ExecuteAsync>d__12.MoveNext() in callback.cshtml
+
        Token: '@ViewData["token"]'
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Razor.RazorView+<RenderPageCoreAsync>d__16.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Razor.RazorView+<RenderPageAsync>d__15.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNetCore.Mvc.Razor.RazorView+<RenderAsync>d__14.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor+<ExecuteAsync>d__22.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor+<ExecuteAsync>d__21.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewResult+<ExecuteResultAsync>d__26.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeResultAsync>d__19.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeNextResultFilterAsync>d__24.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeNextResourceFilter>d__22.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeFilterPipelineAsync>d__17.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeAsync>d__15.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Builder.RouterMiddleware+<Invoke>d__4.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware+<Invoke>d__6.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware+<Invoke>d__6.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+<Invoke>d__7.MoveNext()

VS 2017 asp.net core 2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions