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

时间:2017-08-24 14:45:35

标签: angular angular4-forms ngx-translate

我现在尝试使用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"})

for 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问题还是什么?

来自Ionic: Error: Module build failed: Error: ENOENT: no such file or directory等github上的其他问题和问题  我怀疑在我将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

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

P.S。我没有使用webpack。这2个包需要运行webpack吗?

更新:使用 npm install webpack 抛出

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

在此之后我尝试了:

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

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

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

1 个答案:

答案 0 :(得分:1)

您需要运行此命令 webpack --config webpack.config.js 要么 webpack --config webpack.config.vendor.js 更新你的包后。 如果它没有运行,那么您必须首先使用此命令安装Web包 npm install --global webpack