[英]Angular 5 Error (Angular CLI) - Can't run ng build --prod
I just can't figure this one out.我就是想不通这个。 If I run this locally via ng serve and ng build, it works fine.
如果我通过 ng serve 和 ng build 在本地运行它,它工作正常。 But when I run ng build --prod, it fails with a "Error in ./scr/main.ts. Module not found: Error Can'r resolve './app/app.module.ngFacttory in ...ClientApp\\src"
但是,当我运行 ng build --prod 时,它失败并显示“./scr/main.ts 中的错误。找不到模块:错误无法解析 './app/app.module.ngFactory in ...ClientApp\\”源代码”
I've supplied my main.ts/.angular-cli.json/package.json/app.module.ts.我已经提供了我的 main.ts/.angular-cli.json/package.json/app.module.ts。
What am I missing??我错过了什么??
//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"
}
}
So I found the fix.所以我找到了解决办法。 After cutting multiple pieces out of my app, I finally got a better error message.
从我的应用程序中切出多个部分后,我终于得到了一个更好的错误消息。 A component at a lower level that I wasn't using anymore had a simple error in it, but the VS wasn't telling me that.
我不再使用的较低级别的组件有一个简单的错误,但 VS 没有告诉我。 Once I deleted that component and it's references, the error cleared up.
一旦我删除了该组件及其引用,错误就会消失。 It's a bit frustrating that angular CLI and wepack had such a poor error message.
angular CLI 和 wepack 的错误消息如此糟糕,这有点令人沮丧。 I still don't understand why regular ng build was working, but ng build --prod was failing.
我仍然不明白为什么常规 ng build 有效,但 ng build --prod 失败了。 I would think ng build would fail as well.
我认为 ng build 也会失败。 Regardless, issue resolved
无论如何,问题已解决
I removed:我删除了:
"../node_modules/bootstrap/dist/css/bootstrap.css.map" “../node_modules/bootstrap/dist/css/bootstrap.css.map”
from the angular-cli.json and it worked.来自 angular-cli.json 并且它起作用了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.