由于错误,预渲染失败:错误:无法找到模块"。"在webpackMissingModule

时间:2017-08-24 18:04:04

标签: asp.net angular

我在Visual Studio 2017(版本15.3.2)中使用Angular模板创建了新的Asp.net核心Web应用程序项目。

然后我安装ngx-facebook

{
  "name": "AspNetCoreMvcAngular_Web",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "test": "karma start ClientApp/test/karma.conf.js"
  },
  "dependencies": {
    "@angular/animations": "4.2.5",
    "@angular/common": "4.2.5",
    "@angular/compiler": "4.2.5",
    "@angular/compiler-cli": "4.2.5",
    "@angular/core": "4.2.5",
    "@angular/forms": "4.2.5",
    "@angular/http": "4.2.5",
    "@angular/platform-browser": "4.2.5",
    "@angular/platform-browser-dynamic": "4.2.5",
    "@angular/platform-server": "4.2.5",
    "@angular/router": "4.2.5",
    "@ngtools/webpack": "1.5.0",
    "@types/webpack-env": "1.13.0",
    "angular2-template-loader": "0.6.2",
    "aspnet-prerendering": "^3.0.1",
    "aspnet-webpack": "^2.0.1",
    "awesome-typescript-loader": "3.2.1",
    "bootstrap": "3.3.7",
    "css": "2.2.1",
    "css-loader": "0.28.4",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.9",
    "expose-loader": "0.7.3",
    "extract-text-webpack-plugin": "2.1.2",
    "file-loader": "0.11.2",
    "html-loader": "0.4.5",
    "isomorphic-fetch": "2.2.1",
    "jquery": "3.2.1",
    "json-loader": "0.5.4",
    "ngx-facebook": "^2.4.0",
    "preboot": "4.5.2",
    "raw-loader": "0.5.1",
    "reflect-metadata": "0.1.10",
    "rxjs": "5.4.2",
    "style-loader": "0.18.2",
    "to-string-loader": "1.1.5",
    "typescript": "2.4.1",
    "url-loader": "0.5.9",
    "webpack": "2.5.1",
    "webpack-hot-middleware": "2.18.2",
    "webpack-merge": "4.1.0",
    "zone.js": "0.8.12"
  },
  "devDependencies": {
    "@types/chai": "4.0.1",
    "@types/jasmine": "2.5.53",
    "chai": "4.0.2",
    "jasmine-core": "2.6.4",
    "karma": "1.7.0",
    "karma-chai": "0.1.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-jasmine": "1.1.0",
    "karma-webpack": "2.0.3"
  }
}

将FacebookModule导入应用程序的根模块

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';

import { AppComponent } from './components/app/app.component';
import { NavMenuComponent } from './components/navmenu/navmenu.component';
import { HomeComponent } from './components/home/home.component';
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
import { CounterComponent } from './components/counter/counter.component';

import { FacebookModule } from 'ngx-facebook';

@NgModule({
    declarations: [
        AppComponent,
        NavMenuComponent,
        CounterComponent,
        FetchDataComponent,
        HomeComponent
    ],
    imports: [
        CommonModule,
        HttpModule,
        FormsModule,
        FacebookModule.forRoot(),
        RouterModule.forRoot([
            { path: '', redirectTo: 'home', pathMatch: 'full' },
            { path: 'home', component: HomeComponent },
            { path: 'counter', component: CounterComponent },
            { path: 'fetch-data', component: FetchDataComponent },
            { path: '**', redirectTo: 'home' }
        ])
    ]
})
export class AppModuleShared {
}

尝试注入FacebookService

import { Component } from '@angular/core';
import { FacebookService } from 'ngx-facebook';

@Component({
    selector: 'app',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
}

当我运行项目时,发生错误:NodeInvocationException:由于错误导致预渲染失败:错误:找不到模块"。" http://take.ms/ImVYb

An unhandled exception occurred while processing the request.

NodeInvocationException: Prerendering failed because of error: Error: Cannot find module "."
at webpackMissingModule (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:18316:69)
at Object.defineProperty.value (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:18316:147)
at Object.webpackEmptyContext.keys (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:18325:3)
at __webpack_require__ (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:20:30)
at Object.<anonymous> (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:17769:72)
at __webpack_require__ (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:20:30)
at Object.hasOwn (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:15835:77)
at __webpack_require__ (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:20:30)
at Object.<anonymous> (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:17976:81)
at __webpack_require__ (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:20:30)
Current directory is: C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web
Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance+<InvokeExportAsync>d__7.MoveNext()

Stack Query Cookies Headers
NodeInvocationException: Prerendering failed because of error: Error: Cannot find module "." at webpackMissingModule (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:18316:69) at Object.defineProperty.value (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:18316:147) at Object.webpackEmptyContext.keys (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:18325:3) at __webpack_require__ (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:20:30) at Object.<anonymous> (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:17769:72) at __webpack_require__ (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:20:30) at Object.hasOwn (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:15835:77) at __webpack_require__ (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:20:30) at Object.<anonymous> (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:17976:81) at __webpack_require__ (C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web\ClientApp\dist\main-server.js:20:30) Current directory is: C:\Users\Temirov\Desktop\ASP.NET\AspNetCoreMvcAngular\AspNetCoreMvcAngular.Web
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_Home_Index_cshtml+<ExecuteAsync>d__12.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+<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()

我做错了什么?感谢。

1 个答案:

答案 0 :(得分:0)

我在visual studio 2017中运行时遇到了同样的问题。它在&#39; ./ components / home / home.component&#39;中丢失了一个文件夹。 =&GT; &#39; ./组件/ fetchdata /家/ home.component&#39 ;.

希望这有帮助。