启动应用程序时发生错误,尤其是在Home控制器的Index方法中。
最后采取的措施是对Angular 7.1.4的更新。更新所有其他软件包,删除预引导软件包。
完成这些操作后,在对后端代码进行一些更改之后,该项目正常工作,突然停止了工作。
该项目位于.NET Core 2.1和Angular 7.4.1中。
错误
NodeInvocationException: Can't resolve all parameters for XHRBackend: (?, ?, ?).
Error: Can't resolve all parameters for XHRBackend: (?, ?, ?).
at syntaxError (ProjectPath\ClientApp\dist\vendor.js:9799:21)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver._getDependenciesMetadata (ProjectPath\ClientApp\dist\vendor.js:26048:39)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver._getTypeMetadata (ProjectPath\ClientApp\dist\vendor.js:25941:30)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver._getInjectableTypeMetadata (ProjectPath\ClientApp\dist\vendor.js:26163:25)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver.getProviderMetadata (ProjectPath\ClientApp\dist\vendor.js:26172:26)
at ProjectPath\ClientApp\dist\vendor.js:26110:53
at Array.forEach (<anonymous>)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver._getProvidersMetadata (ProjectPath\ClientApp\dist\vendor.js:26070:23)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver.getNgModuleMetadata (ProjectPath\ClientApp\dist\vendor.js:25789:63)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver.getNgModuleSummary (ProjectPath\ClientApp\dist\vendor.js:25619:39)
日志操作
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost:5000/
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Route matched with {action = "Index", controller = "Home"}. Executing action CTAgenda.Controllers.HomeController.Index (CTAgenda)
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method CTAgenda.Controllers.HomeController.Index (CTAgenda) - Validation state: Valid
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action method CTAgenda.Controllers.HomeController.Index (CTAgenda), returned result Microsoft.AspNetCore.Mvc.ViewResult in 0.9101ms.
info: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor[1]
Executing ViewResult, running view Index.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action CTAgenda.Controllers.HomeController.Index (CTAgenda) in 1582.1294ms
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException: Can't resolve all parameters for XHRBackend: (?, ?, ?).
Error: Can't resolve all parameters for XHRBackend: (?, ?, ?).
at syntaxError (ProjectPath\ClientApp\dist\vendor.js:9799:21)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver._getDependenciesMetadata (ProjectPath\ClientApp\dist\vendor.js:26048:39)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver._getTypeMetadata (ProjectPath\ClientApp\dist\vendor.js:25941:30)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver._getInjectableTypeMetadata (ProjectPath\ClientApp\dist\vendor.js:26163:25)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver.getProviderMetadata (ProjectPath\ClientApp\dist\vendor.js:26172:26)
at ProjectPath\ClientApp\dist\vendor.js:26110:53
at Array.forEach (<anonymous>)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver._getProvidersMetadata (ProjectPath\ClientApp\dist\vendor.js:26070:23)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver.getNgModuleMetadata (ProjectPath\ClientApp\dist\vendor.js:25789:63)
at CompileMetadataResolver.module.exports../node_modules/@angular/compiler/bundles/compiler.umd.js.CompileMetadataResolver.getNgModuleSummary (ProjectPath\ClientApp\dist\vendor.js:25619:39)
at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.InvokeExportAsync[T](NodeInvocationInfo invocationInfo, CancellationToken cancellationToken)
at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.InvokeExportAsync[T](CancellationToken cancellationToken, String moduleName, String exportNameOrNull, Object[] args)
at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.InvokeExportWithPossibleRetryAsync[T](String moduleName, String exportedFunctionName, Object[] args, Boolean allowRetry, CancellationToken cancellationToken)
at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.InvokeExportWithPossibleRetryAsync[T](String moduleName, String exportedFunctionName, Object[] args, Boolean allowRetry, CancellationToken cancellationToken)
at Microsoft.AspNetCore.SpaServices.Prerendering.PrerenderTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.RunAsync(TagHelperExecutionContext executionContext)
at AspNetCore.Views_Home_Index.ExecuteAsync() in ProjectPath\Views\Home\Index.cshtml:line 2
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 3153.7558ms 500 text/html; charset=utf-8
info: Microsoft.AspNetCore.NodeServices[0]
Node will restart because file changed: ProjectPath\wwwroot\dist\0.js
info: Microsoft.AspNetCore.NodeServices[0]
webpack built 6ab4be9f1658a642156f in 64378ms
info: Microsoft.AspNetCore.NodeServices[0]
?[34mi?[39m ?[90m´¢ówdm´¢ú?[39m: Hash: 6ab4be9f1658a642156f
Version: webpack 4.28.3
Time: 64378ms
Built at: 2019-01-08 09:29:14
Asset Size Chunks Chunk Names
0.js 148 KiB 0 [emitted]
0.js.map 81 bytes 0 [emitted]
1.js 100 KiB 1 [emitted]
1.js.map 81 bytes 1 [emitted]
2.js 116 KiB 2 [emitted]
2.js.map 81 bytes 2 [emitted]
3.js 43.8 KiB 3 [emitted]
3.js.map 81 bytes 3 [emitted]
4.js 42.3 KiB 4 [emitted]
4.js.map 81 bytes 4 [emitted]
5.js 3.94 KiB 5 [emitted]
5.js.map 81 bytes 5 [emitted]
main-client.js 2.33 MiB main-client [emitted] main-client
main-client.js.map 34.3 KiB main-client [emitted] main-client
Entrypoint main-client = main-client.js main-client.js.map
info: Microsoft.AspNetCore.NodeServices[0]
?[34mi?[39m ?[90m´¢ówdm´¢ú?[39m: Compiled successfully.
package.json
{
"name": "ctagenda",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"buildWPVendor": "webpack --config webpack.config.vendor.js",
"buildWPDev": "webpack --config webpack.dev.js",
"buildWPProd": "webpack --config webpack.prod.js",
"initConfig": "webpack-cli init",
"statsFile": "webpack --config webpack.prod.js --profile --json | Out-file 'wwwroot/dist/stats.json' -Encoding OEM",
"initTslint": "tslint -i"
},
"private": true,
"dependencies": {
"@angular/animations": "^7.1.4",
"@angular/common": "^7.1.4",
"@angular/compiler": "^7.1.4",
"@angular/core": "^7.1.4",
"@angular/forms": "^7.1.4",
"@angular/http": "^7.1.4",
"@angular/platform-browser": "^7.1.4",
"@angular/platform-browser-dynamic": "^7.1.4",
"@angular/platform-server": "^7.1.4",
"@angular/router": "^7.1.4",
"@ng-bootstrap/ng-bootstrap": "^4.0.1",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^3.0.0",
"bootstrap": "^4.2.1",
"css": "^2.2.4",
"es6-shim": "0.35.4",
"event-source-polyfill": "1.0.5",
"jquery": "3.3.1",
"jwt-decode": "^2.2.0",
"material-design-icons": "^3.0.1",
"moment": "^2.23.0",
"ngx-toastr": "^9.1.1",
"nodemailer": "^5.0.0",
"popper.js": "^1.14.6",
"preboot": "^6.0.0-beta.6",
"reflect-metadata": "0.1.12",
"rxjs": "^6.3.3",
"stacktrace-js": "^2.0.0",
"tslib": "^1.9.3",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/cli": "^7.1.4",
"@angular/compiler-cli": "^7.1.4",
"@angular/language-service": "^7.1.4",
"@ngtools/webpack": "^7.1.4",
"@types/chai": "4.1.7",
"@types/jasmine": "3.3.5",
"@types/jasminewd2": "~2.0.6",
"@types/node": "^10.12.18",
"@types/stacktrace-js": "0.0.32",
"@types/webpack-env": "^1.13.6",
"angular-router-loader": "^0.8.5",
"angular2-template-loader": "^0.6.2",
"chai": "4.2.0",
"codelyzer": "^4.5.0",
"css-loader": "^2.1.0",
"file-loader": "^3.0.1",
"html-loader": "^0.5.5",
"jasmine": "^3.3.1",
"jasmine-core": "3.3.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^3.1.4",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-cli": "2.0.0",
"karma-coverage-istanbul-reporter": "^2.0.4",
"karma-jasmine": "2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"karma-webpack": "^3.0.5",
"mini-css-extract-plugin": "^0.5.0",
"ng-router-loader": "^2.1.0",
"protractor": "^5.4.2",
"style-loader": "^0.23.1",
"to-string-loader": "^1.1.5",
"ts-loader": "^5.3.3",
"ts-node": "~7.0.1",
"tslint": "^5.12.0",
"typescript": "^3.1.6",
"uglifyjs-webpack-plugin": "^2.1.1",
"url-loader": "^1.1.2",
"webpack": "^4.28.3",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-cli": "^3.2.0",
"webpack-dev-middleware": "^3.5.0",
"webpack-hot-middleware": "^2.24.3",
"webpack-merge": "^4.2.1"
}
}
查看Index.cshtml
@{
ViewData["Title"] = "Home Page";
}
<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>
}
boot.server.ts
import { APP_BASE_HREF } from '@angular/common';
import { ApplicationRef, enableProdMode, NgZone } from '@angular/core';
import { INITIAL_CONFIG, platformDynamicServer, PlatformState } from '@angular/platform-server';
import 'reflect-metadata';
import { first } from 'rxjs/operators';
import 'zone.js';
import { createServerRenderer, RenderResult } from 'aspnet-prerendering';
import { AppModule } from './app/app.module.server';
enableProdMode();
export default createServerRenderer((params) => {
const providers = [
{ provide: INITIAL_CONFIG, useValue: { document: '<app></app>', url: params.url } },
{ provide: APP_BASE_HREF, useValue: params.baseUrl },
{ provide: 'BASE_URL', useValue: params.origin + params.baseUrl },
];
return platformDynamicServer(providers).bootstrapModule(AppModule).then((moduleRef) => {
const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
const state = moduleRef.injector.get(PlatformState);
const zone: NgZone = moduleRef.injector.get(NgZone);
const timers: any = require('timers');
return new Promise<RenderResult>((resolve, reject) => {
zone.onError
.subscribe((errorInfo: any) => reject(errorInfo));
appRef.isStable
.pipe(
first((isStable) => isStable)
)
.subscribe(() => {
// Because 'onStable' fires before 'onError', we have to delay slightly before
// completing the request in case there's an error to report
timers.setImmediate(() => {
resolve({
html: state.renderToString()
});
moduleRef.destroy();
});
});
});
});
});
boot.browser.ts
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import 'bootstrap';
import 'reflect-metadata';
import 'zone.js';
import { AppModule } from './app/app.module.browser';
if (module.hot) {
module.hot.accept();
module.hot.dispose(() => {
// Before restarting the app, we create a new root element and dispose the old one
const oldRootElem = document.querySelector('app');
const newRootElem = document.createElement('app');
oldRootElem!.parentNode!.insertBefore(newRootElem, oldRootElem);
modulePromise.then((appModule) => appModule.destroy());
});
} else {
enableProdMode();
}
// Note: @ng-tools/webpack looks for the following expression when performing production
// builds. Don't change how this line looks, otherwise you may break tree-shaking.
const modulePromise = platformBrowserDynamic().bootstrapModule(AppModule);
app.module.shared.ts
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ErrorHandler } from '@angular/core';
import {
NgbDateAdapter,
NgbDateParserFormatter,
NgbDatepickerModule,
NgbModalModule,
NgbTooltipModule
} from '@ng-bootstrap/ng-bootstrap';
import { ToastContainerModule, ToastrModule } from 'ngx-toastr';
import { AppRoutingModule } from './app-routing.module';
import { AppErrorHandler } from './app.error-handler';
import { AppSessionStorage } from './models/shared.model';
import { AppComponent } from './components/app/app.component';
import { ErrorModule } from './components/error/error.module';
import { HomeModule } from './components/home/home.module';
import { LoginModule } from './components/login/login.module';
import { NavMenuModule } from './components/navmenu/navmenu.module';
import { ToolbarModule } from './components/toolbar/toolbar.module';
import { GuardsModule } from './guards/guards.module';
import { InterceptorsModule } from './interceptors/interceptors.module';
import { ServicesModule } from './services/services.module';
import { NgbDateNativeAdapter } from './extensions/ngbDateAdapter.extension';
import { NgbDateGeneralParserFormatter } from './extensions/ngbDateParserFormatter.extension';
@NgModule({
declarations: [
AppComponent
],
imports: [
CommonModule,
GuardsModule,
InterceptorsModule,
ServicesModule,
NavMenuModule,
ToolbarModule,
HomeModule, /* with Routing */
ErrorModule, /* with Routing */
LoginModule, /* with Routing */
AppRoutingModule, /* with Routing */
ToastrModule.forRoot({
positionClass: 'toast-top-center',
preventDuplicates: true,
timeOut: 7000
}),
ToastContainerModule,
NgbDatepickerModule.forRoot(),
NgbModalModule.forRoot(),
NgbTooltipModule.forRoot()
],
providers: [
{ provide: ErrorHandler, useClass: AppErrorHandler },
{ provide: AppSessionStorage, useValue: { getItem() { } } },
{ provide: NgbDateAdapter, useClass: NgbDateNativeAdapter },
{ provide: NgbDateParserFormatter, useClass: NgbDateGeneralParserFormatter }
]
})
export class AppModuleShared {
}
app.module.server.ts
import { NgModule } from '@angular/core';
import { ServerModule } from '@angular/platform-server';
import { AppModuleShared } from './app.module.shared';
import { AppComponent } from './components/app/app.component';
@NgModule({
bootstrap: [ AppComponent ],
imports: [
ServerModule,
AppModuleShared
]
})
export class AppModule {
}
app.module.browser.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppModuleShared } from './app.module.shared';
import { AppComponent } from './components/app/app.component';
import { AppSessionStorage } from './models/shared.model';
@NgModule({
bootstrap: [AppComponent],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppModuleShared
],
providers: [
{ provide: 'BASE_URL', useFactory: getBaseUrl },
{ provide: AppSessionStorage, useValue: window.sessionStorage }
]
})
export class AppModule {
}
export function getBaseUrl() {
return document.getElementsByTagName('base')[0].href;
}