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

window is not defined ReferenceError: window is not defined #33

Closed
zahasoftware opened this issue May 9, 2017 · 3 comments
Closed

window is not defined ReferenceError: window is not defined #33

zahasoftware opened this issue May 9, 2017 · 3 comments

Comments

@zahasoftware
Copy link

zahasoftware commented May 9, 2017

Hi, could you help me please with this error, some other package display the same message, what could be?

The error is in the /dist/main-server.js file.

I'm using a Net Core SPA project with angular 2, if you need more info tell me,
Thanks.

@DethAriel
Copy link
Owner

Hi, and thank you for submitting this! Could you please provide angular and ng-recaptcha versions, as well as the full stack trace to the error? Right now it looks too generic to debug, so the more info you provide - the easier my job would be

@zahasoftware
Copy link
Author

zahasoftware commented May 9, 2017

Ok no problem, first info.

Update2:
project https://yadi.sk/d/2m4QV6GV3HvFuU

Update: I did the project with dotnet command: dotnet new angular

Microsoft .NET Core Shared 

Framework Host

  Version  : 1.1.0
  Build    : 928f77c4bc3f49d892459992fb6e1d5542cb5e86

Usage: dotnet [common-options] [[options] path-to-application]

Common Options:
  --help                           Display .NET Core Shared Framework Host help.
  --version                        Display .NET Core Shared Framework Host version.

Options:
  --fx-version <version>           Version of the installed Shared Framework to use to run the application.
  --additionalprobingpath <path>   Path containing probing policy and assemblies to probe for.

Path to Application:
  The path to a .NET Core managed application, dll or exe file to execute.

If you are debugging the Shared Framework Host, set 'COREHOST_TRACE' to '1' in your environment.

To get started on developing applications for .NET Core, install the SDK from:
  http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

nodejs

node -v 
v6.10.1

npm version
npm@3.3.4

Angular dependencies:

"dependencies": {
    "@angular/common": "^2.4.5",
    "@angular/compiler": "^2.4.5",
    "@angular/core": "^2.4.5",
    "@angular/forms": "^2.4.5",
    "@angular/http": "^2.4.5",
    "@angular/platform-browser": "^2.4.5",
    "@angular/platform-browser-dynamic": "^2.4.5",
    "@angular/platform-server": "^2.4.5",
    "@angular/router": "^3.4.5",
    "@types/node": "^6.0.42",
    "angular2-platform-node": "~2.0.11",
    "angular2-template-loader": "^0.6.2",
    "angular2-universal": "^2.1.0-rc.1",
    "angular2-universal-patch": "^0.2.1",
    "angular2-universal-polyfills": "^2.1.0-rc.1",
    "angular2-jwt": "^0.2.2",
    "aspnet-prerendering": "^2.0.0",
    "aspnet-webpack": "^1.0.17",
    "awesome-typescript-loader": "^3.0.0",
    "bootstrap": "^3.3.7",
    "ng2-bootstrap": "^1.6.3",
    "ng-recaptcha": "^2.1.1",
    "css": "^2.2.1",
    "css-loader": "^0.25.0",
    "es6-shim": "^0.35.1",
    "event-source-polyfill": "^0.0.7",
    "expose-loader": "^0.7.1",
    "extract-text-webpack-plugin": "^2.0.0-rc",
    "file-loader": "^0.9.0",
    "html-loader": "^0.4.4",
    "isomorphic-fetch": "^2.2.1",
    "jquery": "^2.2.1",
    "json-loader": "^0.5.4",
    "preboot": "^4.5.2",
    "raw-loader": "^0.5.1",
    "rxjs": "^5.0.1",
    "style-loader": "^0.13.1",
    "to-string-loader": "^1.1.5",
    "typescript": "^2.2.1",
    "url-loader": "^0.5.7",
    "webpack": "^2.2.0",
    "webpack-hot-middleware": "^2.12.2",
    "webpack-merge": "^0.14.1",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "@types/chai": "^3.4.34",
    "@types/jasmine": "^2.5.37",
    "chai": "^3.5.0",
    "jasmine-core": "^2.5.2",
    "karma": "^1.3.0",
    "karma-chai": "^0.1.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-webpack": "^1.8.0"
  }

Javascript stack
`An unhandled exception occurred while processing the request.
Exception: Call to Node module failed with error: Error: Uncaught (in promise): ReferenceError: window is not defined
ReferenceError: window is not defined
at RecaptchaLoaderService.init
at new RecaptchaLoaderService (---\ClientApp\dist\main-server.js:7095:14)
at NgModuleInjector.get (/AppModule/module.ngfactory.js:234:89)
at NgModuleInjector.AppModuleInjector.getInternal (/AppModule/module.ngfactory.js:482:62)
at NgModuleInjector.get (---\ClientApp\dist\vendor.js:8563:48)
at AppView.injectorGet (---\ClientApp\dist\vendor.js:12008:49)
at ElementInjector.get (---\ClientApp\dist\vendor.js:11863:31)
at ReflectiveInjector_.getByKeyDefault (---\ClientApp\dist\vendor.js:3046:28)
at ReflectiveInjector
.getByKey (---\ClientApp\dist\vendor.js:2981:29)
at ReflectiveInjector
.get (---\ClientApp\dist\vendor.js:2850:25)
at AppView.injectorGet (---\ClientApp\dist\vendor.js:12008:49)
at AppView.View_UserRegisterComponent0.createInternal (/AppModule/UserRegisterComponent/component.ngfactory.js:117:88)
at AppView.create (---\ClientApp\dist\vendor.js:11951:25)
at AppView.View_UserRegisterComponent_Host0.createInternal (/AppModule/UserRegisterComponent/host.ngfactory.js:15:19)
at AppView.createHostView (---\ClientApp\dist\vendor.js:11964:25)
at new Error (native)
at resolvePromise (---\ClientApp\dist\vendor.js:74515:31) [angular]
at resolvePromise (---\ClientApp\dist\vendor.js:74486:17) [angular]
at ---\ClientApp\dist\vendor.js:74563:17 [angular]
at Object.onInvokeTask (---\ClientApp\dist\vendor.js:4044:41) [angular]
at ZoneDelegate.module.exports.ZoneDelegate.invokeTask (---\ClientApp\dist\vendor.js:74216:36) [angular]
at Zone.module.exports.Zone.runTask (---\ClientApp\dist\vendor.js:74016:47) [ => angular]
at drainMicroTaskQueue (---\ClientApp\dist\vendor.js:74396:35) []
at runMicrotasksCallback (internal/process/next_tick.js:64:5) []
at _combinedTickCallback (internal/process/next_tick.js:73:7) []
at process._tickCallback (internal/process/next_tick.js:104:9) []

Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance+d__7.MoveNext()`

I don't know if this stack is usefull, net core stack

Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance+d__7.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance+d__14.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.NodeServices.NodeServicesImpl+d__10.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.NodeServices.NodeServicesImpl+d__10.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.SpaServices.Prerendering.PrerenderTagHelper+d__33.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner+d__0.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
AspNetCore._Views_Home_Index_cshtml+d__31.MoveNext() in Index.cshtml

    ViewData["Title"] = "Home Page";

System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Razor.RazorView+d__14.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Razor.RazorView+d__13.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor+d__18.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewResult+d__26.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__30.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__28.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResultExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__22.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__20.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Builder.RouterMiddleware+d__4.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware+d__5.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware+d__5.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+d__7.MoveNext()

@zahasoftware
Copy link
Author

zahasoftware commented May 9, 2017

I've commented the next line in /Views/Home/Index.cshtml file

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

And I've replaced for this line.

<app></app> 

Or with other words, I've deleted the attribute "asp-prerender-module" of component or tag:

<app>

Ref
http://stackoverflow.com/questions/39719231/how-to-disable-server-side-rendering-on-an-asp-netcore-spa-application/41705938

I can't explain why, but It solve the problem for me.
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

2 participants