angular – 由于错误导致预渲染失败:错误:模块构建失败:错误:ENOENT:没有此类文件或目录,打开

我现在尝试使用ngx-translate或ng2-translate几个月了…

我一直让它走了一段时间,继续开发应用程序的其他部分.

我现在再次尝试使用Core 2,但仍然没有运气.

我创建项目,它完美地工作.我可以改变或创建Angular组件,一切运行良好.

一旦我安装ngx-translate(https://www.npmjs.com/package/@ngx-translate/core)或ng2-translate(https://www.npmjs.com/package/ng2-translate),一切都无效.我遇到的最常见的问题是

NodeInvocationException: Prerendering failed because of error: Error: Module build failed: Error: ENOENT: no such file or directory, open 'C:\Users\Andrei\AngularDefault\SIGAD\node_modules\@angular\platform-server\bundles\platform-server.umd.js'.

我安装时会收到这些警告:

npm install @ ngx-translate / core –save

npm WARN aspnet-webpack@2.0.1 requires a peer of webpack@^1.13.2 || ^2.1.0-beta but none was installed.
npm WARN karma-chai@0.1.0 requires a peer of chai@* but none was installed.
npm WARN karma-jasmine@1.1.0 requires a peer of jasmine-core@* but none was installed.
npm WARN webpack-dev-middleware@1.11.0 requires a peer of webpack@^1.0.0 || ^2.0.0 || ^3.0.0 but none was installed.
npm WARN @ngx-translate/core@7.2.0 requires a peer of @angular/core@>=2.0.0 but none was installed.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.2: wanted {"os":"darwin","arch":"any
"} (current: {"os":"win32","arch":"x64"})

对于npm install @ngx-translate / http-loader

npm WARN @ngx-translate/core@7.2.0 requires a peer of @angular/core@>=2.0.0 but none was installed.
npm WARN aspnet-webpack@2.0.1 requires a peer of webpack@^1.13.2 || ^2.1.0-beta but none was installed.
npm WARN karma-chai@0.1.0 requires a peer of chai@* but none was installed.
npm WARN karma-jasmine@1.1.0 requires a peer of jasmine-core@* but none was installed.
npm WARN webpack-dev-middleware@1.11.0 requires a peer of webpack@^1.0.0 || ^2.0.0 || ^3.0.0 but none was installed.
npm WARN @ngx-translate/http-loader@1.0.2 requires a peer of @angular/core@>=4.3.0 but none was installed.
npm WARN @ngx-translate/http-loader@1.0.2 requires a peer of @angular/common@>=4.3.0 but none was installed.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.2: wanted {"os":"darwin","arch":"any
"} (current: {"os":"win32","arch":"x64"})

这不是我通过“预渲染失败因为……”获得的唯一文件.例如,最奇怪的是如果我下载Mark Pieszak模板https://github.com/MarkPieszak/aspnetcore-angular2-universal.我在错误中得到另一个文件:

NodeInvocationException: Prerendering failed because of error: Error: Module build failed: Error: ENOENT: no such file or directory, open 'C:\Users\Andrei\AngularDefault\SIGAD\node_modules\reflect-metadata\Reflect.js'
at Error (native)

没有我做任何改变……这是一个Windows问题或什么?

来自其他问题和github上的问题,如Ionic: Error: Module build failed: Error: ENOENT: no such file or directory
 我怀疑在将Angular更新到最新版本4.3.6之后,一些软件包已经改变了它们的情况,但我找不到它们.

我没有事件编写代码来使用这些软件包之一…

我的package.json是:

{
  "name": "SIGAD",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "test": "karma start ClientApp/test/karma.conf.js"
  },
  "dependencies": {
    "@angular/animations": "4.3.6",
    "@angular/common": "4.3.6",
    "@angular/compiler": "4.3.6",
    "@angular/compiler-cli": "4.3.6",
    "@angular/core": "4.3.6",
    "@angular/forms": "4.3.6",
    "@angular/http": "4.3.6",
    "@angular/platform-browser": "4.3.6",
    "@angular/platform-browser-dynamic": "4.3.6",
    "@angular/platform-server": "4.3.6",
    "@angular/router": "4.3.6",
    "@ngtools/webpack": "1.6.2",
    "@ngx-translate/core": "^7.2.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.3",
    "bootstrap": "3.3.7",
    "css": "2.2.1",
    "css-loader": "0.28.5",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.9",
    "expose-loader": "0.7.3",
    "extract-text-webpack-plugin": "3.0.0",
    "file-loader": "0.11.2",
    "html-loader": "0.5.1",
    "isomorphic-fetch": "2.2.1",
    "jquery": "3.2.1",
    "json-loader": "0.5.7",
    "preboot": "5.0.0",
    "raw-loader": "0.5.1",
    "reflect-metadata": "0.1.10",
    "rxjs": "5.4.3",
    "style-loader": "0.18.2",
    "to-string-loader": "1.1.5",
    "typescript": "2.4.2",
    "url-loader": "0.5.9",
    "webpack": "3.5.5",
    "webpack-hot-middleware": "2.18.2",
    "webpack-merge": "4.1.0",
    "zone.js": "0.8.17"
  },
  "devDependencies": {
    "@types/chai": "4.0.4",
    "@types/jasmine": "2.5.54",
    "chai": "4.1.1",
    "jasmine-core": "2.7.0",
    "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.4"
  }
}

我的app.module.ts是:

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 { UserComponent } from "./components/user/user.component";
import { ErrorComponent } from "./components/error/error.component";

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

            { path: 'user', component: UserComponent },
            { path: 'error', component: ErrorComponent },

            { path: '**', redirectTo: 'home' }
        ])
    ]
})
export class AppModuleShared {
}

GIT存储库在这里https://github.com/dobrinsky/AngularDefault.

请帮助…这很难理解为什么不工作因为每个人都很容易使用…

附:我没有使用webpack.这2个包需要运行webpack吗?

更新:使用npm install webpack throws

NodeInvocationException: Can't resolve all parameters for HttpXsrfCookieExtractor: (?, [object Object], [object Object])

在此之后我尝试了:

>完全卸载节点(以及任何版本管理器/等)
>转到%AppData%/漫游删除任何npm或npm缓存文件夹
>重新启动计算机,安装最新的节点6. *
> npm i -g webpack

安装时我没有收到上述警告,但现在我得到:

Prerendering failed because of error: Error: Module build failed: TypeError: loaderUtils.getOptions is not a function

最佳答案 你需要运行这个命令

webpack –config webpack.config.js

要么

webpack –config webpack.config.vendor.js

更新你的包后.

如果它没有运行,那么您必须首先使用此命令安装Web包

npm install –global webpack

点赞