【问题标题】:NodeInvocationException: localStorage is not definedNodeInvocationException:未定义本地存储
【发布时间】:2018-03-10 05:44:28
【问题描述】:

我正在使用 asp.net core 2.0 AngularJS 模板,当我尝试在 AppComponent 中使用 localStorage 时显示

NodeInvocationException: localStorage 未定义 ReferenceError: localStorage 未定义。

我浪费了很多时间来解决这个问题,不幸的是 angular2-universal 甚至没有使用 asp.net core 2.0 来检查条件 isBrowser。事件 localStorage 也不能与 HomeComponent 一起使用。

我该如何解决这个问题。请帮我解决这个问题。谢谢。

export class AppComponent {

constructor() {

    localStorage.setItem('count', 'not set');
    console.log('const');
}

}

【问题讨论】:

  • 这并没有解决我的问题。实际上我可以在 CounterComponent 和 FetchDataComponent 中使用 localStorage。只有 HomeComponent 和 AppComponent 在我的模板中才会发生。
  • 我也有类似的问题。我注释掉了所有本地存储代码并再次运行 Web 应用程序,然后我得到了一个不同的错误。 NodeInvocationException: The Node invocation timed out after 60000ms. You can change the timeout duration by setting the InvocationTimeoutMilliseconds property on NodeServicesOptions. The first debugging step is to ensure that your Node.js function always invokes the supplied callback (or throws an exception synchronously), even if it encounters an error. Otherwise, the .NET code has no way to know that it is finished or has failed.

标签: angularjs


【解决方案1】:

似乎有人在 Github (https://github.com/MarkPieszak/aspnetcore-angular2-universal/issues/238) 上发布了类似的问题。

我认为某处存在 Angular 错误,但由于 VS Angular 模板使用 Webpack 构建 Angular 应用程序,它被报告为其他错误。我认为 Webpack 应用程序无法构建,并且 ASP.Net Core 没有报告潜在问题。

【讨论】:

    猜你喜欢
    • 2020-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-07
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多