Angular 角度5错误(角度CLI)-Can';t运行ng构建--prod

Angular 角度5错误(角度CLI)-Can';t运行ng构建--prod,angular,Angular,我就是搞不懂这个。如果我通过ng SERVICE和ng build在本地运行它,它工作得很好。但当我运行ng build--prod时,它会失败,并出现“未找到./scr/main.ts.Module中的错误:错误无法解决”。/app/app.Module.ngfactory in…ClientApp\src” 我已经提供了main.ts/.angular-cli.json/package.json/app.module.ts 我错过了什么 //main.ts import { enablePr

我就是搞不懂这个。如果我通过ng SERVICE和ng build在本地运行它,它工作得很好。但当我运行ng build--prod时,它会失败,并出现“未找到./scr/main.ts.Module中的错误:错误无法解决”。/app/app.Module.ngfactory in…ClientApp\src”

我已经提供了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"
  }
}

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

我已删除:

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


从angular-cli.json中,它成功了。

您应该检查get base url函数。也许你想以编程方式设置基本URL,你可以考虑使用AppHythBuyHeRf作为。我不知道你的意思是什么?我的main.ts有什么问题吗?是的,我想你应该检查一下你的main.tsI把它改成这个。还是有同样的问题。从“@angular/core”导入{enableProdMode};从“@angular/platformBrowserDynamic”导入{platformBrowserDynamic};从“./app/app.module”导入{AppModule};从“./environments/environment”导入{environment};if(environment.production){enableProdMode();}platformBrowserDynamic().bootstrapModule(AppModule).catch(err=>console.log(err));安格尔把球落在了这上面。为什么开发人员现在在构建时突然没有显示错误?有几个小时的bug。