--prod Build发出警告,升级到Angular 7后部署的应用程序未加载
我最近将现有的Angular 6应用升级到Angular 7。我的大部分应用程序都是基于Angular 6构建的,然后我升级了它 这是我的package.json:--prod Build发出警告,升级到Angular 7后部署的应用程序未加载,angular,angular-cli,angular7,Angular,Angular Cli,Angular7,我最近将现有的Angular 6应用升级到Angular 7。我的大部分应用程序都是基于Angular 6构建的,然后我升级了它 这是我的package.json: { "name": "app-name", "version": "0.0.0", "scripts": { "ng": "ng", "start"
{
"name": "app-name",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@agm/core": "^1.0.0-beta.5",
"@angular/animations": "^7.0.0",
"@angular/cdk": "^7.0.0",
"@angular/common": "^7.0.0",
"@angular/compiler": "^7.0.0",
"@angular/core": "^7.0.0",
"@angular/fire": "^5.0.2",
"@angular/forms": "^7.0.0",
"@angular/http": "^7.0.0",
"@angular/material": "^7.0.0",
"@angular/platform-browser": "^7.0.0",
"@angular/platform-browser-dynamic": "^7.0.0",
"@angular/router": "^7.0.0",
"bootstrap": "^4.1.3",
"core-js": "^2.5.4",
"firebase": "^5.5.1",
"npm": "^6.4.1",
"rxjs": "^6.3.3",
"sweetalert2": "^7.28.7",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.6.8",
"@angular/cli": "~7.0.2",
"@angular/compiler-cli": "^7.0.0",
"@angular/language-service": "^7.0.0",
"@types/googlemaps": "^3.30.13",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~3.1.3"
}
}
下面是我在运行ng build--prod
时收到的警告:
C:\Development\Angular\MyApp>ng build --prod
Date: 2018-10-24T17:36:28.367Z
Hash: a03e526b7e8175b25c06
Time: 32695ms
chunk {0} 0.cafd68819f30185de9af.js () 74.8 kB [rendered]
chunk {1} 1.00224f689303f6e8aae8.js () 33.7 kB [rendered]
chunk {2} 2.c9d485747518d5177cf8.js () 29.7 kB [rendered]
chunk {3} 3.e25546a8136eb13e9af3.js () 31.5 kB [rendered]
chunk {4} 4.120580aa06e187956a3a.js () 51.3 kB [rendered]
chunk {5} 5.890208a2f9c910b04821.js () 62.8 kB [rendered]
chunk {6} 6.659eb84df5c798c5ff39.js () 29.4 kB [rendered]
chunk {7} runtime.4ee86023cc00ae14666e.js (runtime) 1.99 kB [entry] [rendered]
chunk {8} styles.f6067b501f9d2a5208bf.css (styles) 215 kB [initial] [rendered]
chunk {9} polyfills.644a401562606166b860.js (polyfills) 59.6 kB [initial] [rendered]chunk {10} main.be4cab576441165d61f9.js (main) 1.13 MB [initial] [rendered]
WARNING in ./src/app/tv/components/add-program-card/add-program-card.component.ngfactory.js
31:52-87 "export 'ɵangular_packages_forms_forms_bh' (imported as 'i2') was not found in '@angular/forms'
WARNING in ./src/app/tv/components/edit-program-card/edit-program-card.component.ngfactory.js
31:52-87 "export 'ɵangular_packages_forms_forms_bh' (imported as 'i2') was not found in '@angular/forms'
WARNING in ./src/app/news/components/edit-article-card/edit-article-card.component.ngfactory.js
33:52-87 "export 'ɵangular_packages_forms_forms_bh' (imported as 'i2') was not found in '@angular/forms'
WARNING in ./src/app/news/components/add-news-card/add-news-card.component.ngfactory.js
33:52-87 "export 'ɵangular_packages_forms_forms_bh' (imported as 'i2') was not found in '@angular/forms'
WARNING in ./src/app/team/components/add-player-card/add-player-card.component.ngfactory.js
33:52-87 "export 'ɵangular_packages_forms_forms_bh' (imported as 'i2') was not found in '@angular/forms'
WARNING in ./src/app/team/components/edit-player-card/edit-player-card.component.ngfactory.js
33:52-87 "export 'ɵangular_packages_forms_forms_bh' (imported as 'i2') was not found in '@angular/forms'
WARNING in ./src/app/boutique/components/add-merchandise-card/add-merchandise-card.component.ngfactory.js
39:52-87 "export 'ɵangular_packages_forms_forms_bh' (imported as 'i6') was not found in '@angular/forms'
WARNING in ./src/app/boutique/components/edit-merchandise-card/edit-merchandise-card.component.ngfactory.js
39:52-87 "export 'ɵangular_packages_forms_forms_bh' (imported as 'i6') was not found in '@angular/forms'
WARNING in ./src/app/games/components/edit-game-card/edit-game-card.component.ngfactory.js
45:52-87 "export 'ɵangular_packages_forms_forms_bh' (imported as 'i2') was not found in '@angular/forms'
WARNING in ./src/app/games/components/add-game-card/add-game-card.component.ngfactory.js
45:52-87 "export 'ɵangular_packages_forms_forms_bh' (imported as 'i2') was not found in '@angular/forms'
WARNING in ./src/app/components/login/login.component.ngfactory.js
49:53-88 "export 'ɵangular_packages_forms_forms_bh' (imported as 'i5') was not found in '@angular/forms'
一开始我对这些警告没有太多考虑。但当我尝试导航到Firebase Hosting上托管的应用程序时,我的应用程序未加载,并且在控制台上也出现以下错误:
Uncaught TypeError: e is not a constructor
at main.be4cab576441165d61f9.js:1
at Xr (main.be4cab576441165d61f9.js:1)
at main.be4cab576441165d61f9.js:1
at new t (main.be4cab576441165d61f9.js:1)
at Object.mi [as createNgModuleRef] (main.be4cab576441165d61f9.js:1)
at e.create (main.be4cab576441165d61f9.js:1)
at main.be4cab576441165d61f9.js:1
at e.invoke (polyfills.644a401562606166b860.js:1)
at Object.onInvoke (main.be4cab576441165d61f9.js:1)
at e.invoke (polyfills.644a401562606166b860.js:1)
到目前为止我尝试过的事情:
角形文件包\u表单\u表单\u bh
,发现该文件在中引用,并在大约20分钟前更新,但不知道该如何处理
src/index.ts
到现在还没有的所有内容
SharedModule
中创建了一个自定义表单控件元素,它实现了ControlValueAccessor
。以下是相同的模板:
import { Component, EventEmitter, forwardRef, HostBinding, Input, OnInit, Output } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Observable } from 'rxjs';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { map, startWith } from 'rxjs/operators';
@Component({
selector: 'app-category-list',
templateUrl: './category-list.component.html',
styleUrls: ['./category-list.component.scss'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => CategoryListComponent),
multi: true
}
]
})
export class CategoryListComponent implements OnInit, ControlValueAccessor {
myControl = new FormControl();
selectedValue;
filteredOptions: Observable<string[]>;
question = 'Would you like to add ';
@Input() options: string[];
@Output() added = new EventEmitter();
// Function to call when the option changes.
onChange(option: string) {
}
// Function to call when the input is touched (when the autocomplete is clicked).
onTouched() {
}
get value() {
return this.selectedValue;
}
ngOnInit() {
this.filteredOptions = this.myControl.valueChanges
.pipe(
startWith(''),
map(option => option ? this.filter(option) : this.options.slice())
);
}
optionSelected(option) {
if (option.value.indexOf(this.question) === 0) {
const newOption = option.value.substring(this.question.length).split('?')[0];
this.options.push(newOption);
this.added.emit(newOption);
this.myControl.setValue(newOption);
this.writeValue(newOption);
} else {
this.myControl.setValue(option.value);
this.writeValue(option.value);
}
}
enter() {
const controlValue = this.myControl.value;
if (!this.options.some(entry => entry === controlValue)) {
this.added.emit(controlValue);
const index = this.options.push(controlValue);
setTimeout(
() => {
this.myControl.setValue(controlValue);
this.writeValue(controlValue);
}
);
} else {
this.writeValue(controlValue);
}
}
// Allows Angular to update the model (option).
// Update the model and changes needed for the view here.
writeValue(option: string): void {
console.log(`writeValue called with ${option}`);
this.selectedValue = option;
this.myControl.setValue(option);
this.onChange(option);
}
// Allows Angular to register a function to call when the model (rating) changes.
// Save the function as a property to call later here.
registerOnChange(fn: (option: string) => void): void {
this.onChange = fn;
}
// Allows Angular to register a function to call when the input has been touched.
// Save the function as a property to call later here.
registerOnTouched(fn: () => void): void {
this.onTouched = fn;
}
private filter(value: string): string[] {
let results;
if (value) {
results = this.options
.filter(option => option.toLowerCase().indexOf(value.toLowerCase()) === 0);
if (results.length < 1) {
results = [this.question + value + '?'];
}
} else {
results = this.options.slice();
}
return results;
}
}
从'@angular/core'导入{Component,EventEmitter,forwardRef,HostBinding,Input,OnInit,Output};
从'@angular/forms'导入{FormControl};
从“rxjs”导入{Observable};
从'@angular/forms'导入{ControlValueAccessor,NG_VALUE_ACCESSOR};
从“rxjs/operators”导入{map,startWith};
@组成部分({
选择器:“应用程序类别列表”,
templateUrl:'./category list.component.html',
样式URL:['./类别列表.component.scss'],
供应商:[
{
提供:NG_值访问器,
useExisting:forwardRef(()=>CategoryListComponent),
多:真的
}
]
})
导出类CategoryListComponent实现OnInit、ControlValueAccessor{
myControl=newformcontrol();
选择值;
过滤装置:可观察;
问题='您想添加'吗;
@输入()选项:字符串[];
@添加的输出()=新的EventEmitter();
//当选项更改时调用的函数。
onChange(选项:字符串){
}
//触摸输入时(单击自动完成时)调用的函数。
未触及的(){
}
获取值(){
返回此.selectedValue;
}
恩戈尼尼特(){
this.filteredOptions=this.myControl.valueChanges
.烟斗(
startWith(“”),
映射(option=>option?this.filter(option):this.options.slice()
);
}
选项已选(选项){
if(option.value.indexOf(this.question)==0){
const newOption=option.value.substring(this.question.length).split(“?”)[0];
this.options.push(newOption);
this.added.emit(newOption);
this.myControl.setValue(newOption);
此.writeValue(新选项);
}否则{
this.myControl.setValue(option.value);
this.writeValue(option.value);
}
}
输入(){
const controlValue=this.myControl.value;
如果(!this.options.some(entry=>entry==controlValue)){
this.added.emit(controlValue);
const index=this.options.push(控制值);
设置超时(
() => {
this.myControl.setValue(controlValue);
this.writeValue(controlValue);
}
);
}否则{
this.writeValue(controlValue);
}
}
//允许Angular更新模型(选项)。
//在此更新视图所需的模型和更改。
writeValue(选项:字符串):无效{
log(`writeValue调用时使用${option}`);
this.selectedValue=选项;
this.myControl.setValue(选项);
此.onChange(选项);
}
//允许Angular在模型(额定值)更改时注册要调用的函数。
//将函数另存为属性,以便稍后在此调用。
registerOnChange(fn:(选项:字符串)=>void:void{
this.onChange=fn;
}
//允许Angular在触摸输入时注册要调用的函数。
//将函数另存为属性,以便稍后在此调用。
注册表项(fn:()=>void):void{
this.ontoched=fn;
}
专用筛选器(值:字符串):字符串[]{
让结果;
如果(值){
结果=此选项
.filter(option=>option.toLowerCase().indexOf(value.toLowerCase())==0);
如果(结果长度<1){
结果=[this.question+value+'?'];
}
}否则{
结果=this.options.slice();
}
返回结果;
}
}
这些警告与此有关吗?从Angular 6升级到Angular 7后,我收到了相同的警告和错误。 我已删除了我的节点\u模块文件夹,然后再次npm安装。
现在编译成功了,没有任何警告,我不再有错误“UncaughtTypeError:e不是构造函数”。这里的正确方向是一步一步地剪切不相关的代码,以提供最小的reproduction@yurzui,我不太明白你的意思。顺便说一句,我已经更新了我的问题。你能检查一下这是否是这些警告的原因,从而导致了问题吗?@yurzui建议创建一个——或者更确切地说,在仍然出现错误的情况下尽可能多地删除代码。也可以做相反的事情:删除代码片段,直到错误不再出现。无论哪种方式,这都会显示导致问题的应用程序部分。这将使确定问题所在变得更容易。我早该这样做的。无论如何非常感谢您的帮助:)