简体   繁体   English

找不到模块:错误:无法解析'./$$_gendir/app/app.module.ngfactory'

[英]Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'

just yesterday my code was working fine, made no changes to the app module and today when using "ng build --prod" I get this error. 就在昨天我的代码工作正常,没有对应用程序模块进行任何更改,今天使用“ng build --prod”时出现此错误。 I know that it's not related to changes, when I pull older branches I get the same error. 我知道它与变化无关,当我拉老分支时,我得到同样的错误。 I don't know what to do, a recommendation was to update each package, but even after I still get the same error. 我不知道该怎么做,建议更新每个包,但即使我仍然得到相同的错误。 Not even sure if you guys can help, but here's my app.module: 甚至不确定你们是否可以提供帮助,但这是我的app.module:

import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {HttpModule} from '@angular/http';

import {AppComponent} from './app.component';
import {LoginComponent} from './login/login.component';
import {CompareComponent} from './compare/compare.component';
import {RouterModule} from "@angular/router";
import {CompareCardComponent} from './compare/compare-card/compare-card.component';
import {LayoutComponent} from './layout/layout.component';
import {CompareValuePipe} from "./compare/compare-card/compare-card.pipe";
import {HomeComponent} from './home/home.component';
import {NewLocationComponent} from './new-location/new-location.component';
import {SignupComponent} from './signup/signup.component';
import {ValidateMe} from "./shared/me.suite/validate.me/validate.me";
import {TagsComponent} from './tags/tags.component';
import {GoogleplaceDirective} from './third-party/angular2-google-map-auto-complete/directives/googleplace.directive';
import { LoaderComponent } from './shared/loader/loader.component';
import { AlertComponent } from './shared/alert/alert.component';
import {Angulartics2GoogleAnalytics, Angulartics2Module} from "angulartics2";
import { OverallPipe } from './compare/overall.pipe';
import {InteractiveComponent} from "./question/interactive/interactive.component";
import { FormComponent } from './question/form/form.component';
import { KpiDescComponent } from './compare/kpi-desc/kpi-desc.component';
import {HashLocationStrategy, Location, LocationStrategy} from "@angular/common";
import {AccountApi} from "./services/account-api.service";
import {SettingsApi} from "./services/settings-api.service";
import {DataApi} from "./services/data-api.service";
import { ZeezorInfoComponent } from './zeezor-info/zeezor-info.component';

const ROUTES = [
    {path: '', redirectTo: '/home', pathMatch: 'full'},
    {path: 'compare', component: CompareComponent},
    {path: 'new', component: NewLocationComponent},
    {path: 'tags', component: TagsComponent},
    {path: 'interactive', component: InteractiveComponent},
    {path: 'form', component: FormComponent},
    {path: 'login', component: LoginComponent},
    {path: 'signup', component: SignupComponent},
    {path: 'home', component: HomeComponent},
    {path: '**', component: HomeComponent}
];

@NgModule({
    declarations: [
        LayoutComponent,
        AppComponent,
        LoginComponent,
        CompareComponent,
        CompareCardComponent,
        CompareValuePipe,
        InteractiveComponent,
        HomeComponent,
        NewLocationComponent,
        SignupComponent,
        ValidateMe,
        TagsComponent,
        GoogleplaceDirective,
        LoaderComponent,
        AlertComponent,
        OverallPipe,
        FormComponent,
        KpiDescComponent,
        ZeezorInfoComponent
    ],
    imports: [
        BrowserModule,
        FormsModule,
        HttpModule,
        RouterModule.forRoot(ROUTES),
        Angulartics2Module.forRoot([ Angulartics2GoogleAnalytics ])
    ],
    providers: [AccountApi, DataApi, SettingsApi, Location, {provide: LocationStrategy, useClass: HashLocationStrategy}],
    bootstrap: [AppComponent]
})
export class AppModule {
    constructor(){
        let style = document.createElement('link');
        style.rel = "stylesheet";
        style.href = SettingsApi.styleEndpoint;
        window.document.head.appendChild(style);
        console.log(navigator.userAgent);
    }
}

Package.json 的package.json

{
  "name": "stack-up",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "compile": "ng build --environment=mobile --output-path ../mobile/www/",
    "compile:prod": "ng build --environment=mobile --target=production --output-path ../mobile/www/",
    "docker": "ng build --environment=docker",
    "local": "ng serve --environment=local",
    "dev": "ng build --environment=dev",
    "prod": "ng build --environment=prod --target=production --output-path /var/www/html/"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^2.4.0",
    "@angular/compiler": "^2.4.0",
    "@angular/core": "^2.4.0",
    "@angular/forms": "^2.4.0",
    "@angular/http": "^2.4.0",
    "@angular/platform-browser": "^2.4.0",
    "@angular/platform-browser-dynamic": "^2.4.0",
    "@angular/router": "^3.4.0",
    "angular2-jwt": "^0.2.2",
    "angular2-social-login": "^2.1.0",
    "angulartics2": "^2.2.1",
    "core-js": "^2.4.1",
    "rxjs": "^5.0.1",
    "ts-helpers": "^1.1.1",
    "tslint": "^3.15.1",
    "zone.js": "^0.7.2"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0-beta.31",
    "@angular/compiler-cli": "^2.4.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "protractor": "~5.1.0",
    "ts-node": "1.2.1",
    "tslint": "^4.3.0",
    "typescript": "~2.0.0"
  }
}

I had a similar problem yesterday (same error message) and I fixed it based on this angular-cli issue: 我昨天遇到了类似的问题(相同的错误信息),我根据这个angular-cli问题修复了它:

https://github.com/angular/angular-cli/issues/7125 https://github.com/angular/angular-cli/issues/7125

The fix was to pin enhanced-resolve to version 3.3.0 in my package.json, delete node_modules, run npm install , then build again. 修复是在我的package.json中将enhanced-resolveenhanced-resolve为版本3.3.0 ,删除node_modules,运行npm install ,然后再次构建。 This seems to have fixed the problem for some of the people in the issue thread. 这似乎解决了问题线程中一些人的问题。

The newer version of enhanced-resolve seems to be causing some problem. 较新版本的enhanced-resolve似乎导致了一些问题。

If it still breaks make sure you have the correct enhanced-resolve version by running npm ls enhanced-resolve . 如果它仍然中断,请通过运行npm ls enhanced-resolve确保您具有正确的增强版解析版本。

For anyone else coming accross this, there was a descrepency with older versions of angular-cli and angular . 对于其他任何人来说,对于旧版本的angular-cliangular ,存在着一种不确定性。 Source . 来源

To resolve this, upgrade angular-cli to @latest . 要解决此问题, @latest angular-cli升级到@latest

 npm uninstall -g angular-cli npm cache clean npm install -g @angular/cli@latest 

Depending on your system, you may need to prefix the above commands with sudo. 根据您的系统,您可能需要使用sudo为上述命令添加前缀。

Also, most likely you want to also update your local project version, because inside your project directory it will be selected with higher priority than the global one: 此外,您很可能还想更新本地项目版本,因为在项目目录中,它的选择优先级高于全局项目:

 rm -rf node_modules npm uninstall --save-dev angular-cli npm install --save-dev @angular/cli@latest npm install 

How to upgrade Angular CLI to the latest version 如何将Angular CLI升级到最新版本

If you don't want to use @latest angular-cli, update @angular-cli at least to v1.2.6. 如果您不想使用@latest angular-cli,请将@ angular-cli至少更新为v1.2.6。 It's solved issue for now and you don't need to install enhanced-resolve and so on. 它现在解决了问题,你不需要安装增强解析等等。 https://github.com/angular/angular-cli/issues/7113 https://github.com/angular/angular-cli/issues/7113

在此输入图像描述 As mentioned in the previous answer, the enahnced-resolve version 3.4.1 was causing the issue. 如前面的答案所述,enahnced-resolve版本3.4.1导致了这个问题。 Using version 3.3.0 fixes the issue. 使用版本3.3.0修复了该问题。 We can pin the dpendencies versions using nopm-srinkwrap.json 我们可以使用nopm-srinkwrap.json来固定dpendencies版本

I just ran into this issue today. 我今天刚遇到这个问题。 I tried running the command: 我试过运行命令:

ng build --env=prod instead of ng build --prod and it seems to have solved it without adding enhanced-resolve in the package.json. ng build --env = prod而不是ng build --prod,它似乎解决了它而没有在package.json中添加enhanced-resolve。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到模块:错误:无法解析“ ./$$_gendir/app/app.app.module.ngfactory” - Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' 找不到模块:错误:无法解析'./$$_gendir/app/app.module.ngfactory' - Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in Angular 4错误-./src/main.ts中找不到错误:错误:无法解析'./$$_gendir/app/app.app.module.ngfactory' - Angular 4 error - ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' 找不到模块:错误:无法解析$$ _ gendir \\ app \\ item-receive-return.module.ngfactory.ts' - Module not found: Error: Can't resolve $$_gendir\app\item-receive-return.module.ngfactory.ts' 找不到模块:错误:无法解析'./app.module.ngfactory'-离子3,角度5 - Module not found: Error: Can't resolve './app.module.ngfactory' - ionic 3, angular 5 ./ClientApp/boot.server.ts中的错误找不到模块:错误:无法解析'./../$$_gendir/ClientApp/app/app.app.server.module.ngfactory' - ERROR in ./ClientApp/boot.server.ts Module not found : error : Can't resolve './../$$_gendir/ClientApp/app/app.server.module.ngfactory' ./src/main.ts中的ngcli 6.1.3错误-无法解析'./app/app.module.ngfactory' - ngcli 6.1.3 ERROR in ./src/main.ts - Can't resolve './app/app.module.ngfactory' ./src/main/webapp/app/app.main.ts 中的 Jhipster webpack 生产错误,找不到模块:错误:无法解析“./app.module.ngfactory” - Jhipster webpack production ERROR in ./src/main/webapp/app/app.main.ts ,Module not found:Error: Can't resolve './app.module.ngfactory' AOT-找不到加载错误app.module.ngfactory - AOT - loading error app.module.ngfactory is not found 错误:无法解析“ C:\\ projects \\ Project-CMS \\ Project.Web \\ src”中的“ ./app/app.module.ngfactory” - Error: Can't resolve './app/app.module.ngfactory' in 'C:\projects\Project-CMS\Project.Web\src'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM