Angular 5错误(Angular CLI) - 无法运行build --prod

时间:2018-01-02 02:56:46

标签: angular

Angular Error message

我无法解决这个问题。如果我通过ng serve和ng build在本地运行它,它可以正常工作。但是当我运行build -prod时,它会在./scr/main.ts中出现"错误。找不到模块:错误无法在... ClientApp \ src"

中解析' ./ app / app.module.ngFacttory

我已经提供了我的main.ts / .angular-cli.json / package.json / app.module.ts。

我错过了什么?

//main.ts
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

export function getBaseUrl() {
  return document.getElementsByTagName('base')[0].href;
}

const facilitys = [
  { provide: 'BASE_URL', useFactory: getBaseUrl, deps: [] }
];

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic(facilitys).bootstrapModule(AppModule)
  .catch(err => console.log(err));

//app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router';
import { HttpModule } from '@angular/http';
import { ReactiveFormsModule } from '@angular/forms';
import { CommonModule} from "@angular/common";

import { AppComponent } from './app.component';
import { NavMenuComponent } from './nav-menu/nav-menu.component';
import { HomeComponent } from './home/home.component';

import { MentalHealthService } from './service/mental.health.service';
import { AppRoutingModule } from './app-routing.module';
import { ProviderModule } from "./provider/provider.module";
import { FacilityModule } from "./facility/facility.module";
import { VendorModule } from "./vendor/vendor.module";



@NgModule({
  declarations: [
    AppComponent,
    NavMenuComponent,
    HomeComponent
  ],
  imports: [
    BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
    HttpClientModule,
    FormsModule,
    HttpModule,
    ReactiveFormsModule,
    ProviderModule,
    FacilityModule,
    VendorModule,
    AppRoutingModule,
    CommonModule
  ],
  exports: [
    CommonModule,
    FormsModule],
  providers: [MentalHealthService],
  bootstrap: [AppComponent]
})
export class AppModule { }

//Angular-cli.json
{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "AngularTemplate"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.css",
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "../node_modules/font-awesome/css/font-awesome.css"

      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "../node_modules/popper.js/dist/umd/popper.min.js",
        "../node_modules/bootstrap/dist/js/bootstrap.min.js"

      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {},
    "build": {
      "progress": true
    }
  }
}

//package.json
{
  "name": "AngularTemplate",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --extract-css",
    "build": "ng build --extract-css",
    "build:ssr": "npm run build -- --app=ssr --output-hashing=media",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/schematics": "0.0.40",
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/platform-server": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.8",
    "@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5",
    "D": "^1.0.0",
    "angular-basic-modal": "^4.1.0",
    "aspnet-prerendering": "^3.0.1",
    "bootstrap": "^4.0.0-beta.2",
    "core-js": "^2.4.1",
    "enhanced-resolve": "^3.3.0",
    "font-awesome": "^4.7.0",
    "jquery": "^3.2.1",
    "popper": "^1.0.1",
    "popper.js": "^1.12.9",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.6.0",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }
}

2 个答案:

答案 0 :(得分:3)

所以我找到了解决办法。从我的应用程序中删除多个部分后,我终于得到了更好的错误消息。我不再使用的较低级别的组件有一个简单的错误,但VS没有告诉我。删除该组件及其引用后,错误就被清除了。角度CLI和wepack有如此糟糕的错误消息,这有点令人沮丧。我仍然不明白为什么常规的ng build工作正常,但ng build --prod失败了。我认为构建也会失败。无论如何,问题已解决

答案 1 :(得分:0)

我删除了:

“ ../ node_modules / bootstrap / dist / css / bootstrap.css.map”

从angular-cli.json开始,并且有效。