Angular 6在--prod标志下失败
您好,我在使用Angular CLI近2年后面临此错误。我在谷歌上搜索,找不到任何解决这个问题的方法Angular 6在--prod标志下失败,angular,angular6,Angular,Angular6,您好,我在使用Angular CLI近2年后面临此错误。我在谷歌上搜索,找不到任何解决这个问题的方法 Can't resolve all parameters for BaseService in E:/**/web/src/app/shared/services/base.service.ts: ([object Object], ?, ?, ?). This will become an error in Angular v6.x 当我运行这个命令时 ng build --output
Can't resolve all parameters for BaseService in E:/**/web/src/app/shared/services/base.service.ts: ([object Object], ?, ?, ?). This will become an error in Angular v6.x
当我运行这个命令时
ng build --output-hashing none --prod --build-optimizer=false
当我使用--prod标记构建时,Angular无法构建。它显示了一个随机错误,例如:
ERROR in : Unexpected value 'component in E:/**/web/src/app/shared/index.ts' imported by the module 'BlotterModule in E:/***/web/src/app/modules/blotter/blotter.module.ts'. Please add a @NgModule annotation.
错误中提到的索引文件是
import * as Services from './services';
import * as directives from './directives';
import * as pipes from './pipes';
import * as component from './components';
import * as guards from './guards';
export {
component,
Services,
directives,
pipes,
guards
}
我的package.json文件是
{
"name": "epricing",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng build --watch --output-hashing none && ng serve -o --proxy-config proxy.config.json ",
"build": "ng build --extract-css",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"mi:prod": "ng build --output-hashing none --base-href /DevInet.ePricing.MultiTaux.Web/",
"run:prod": "ng build --output-hashing none --prod --build-optimizer=false --base-href /DevInet.ePricing.MultiTaux.Web/"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.10",
"@angular/cdk": "^7.0.2",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/material": "^7.0.2",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"@ng-bootstrap/ng-bootstrap": "^2.0.0",
"@ng-select/ng-select": "^2.9.1",
"@ngrx/effects": "^6.1.0",
"@ngrx/entity": "^6.1.0",
"@ngrx/store": "^6.1.0",
"@ngrx/store-devtools": "^6.1.0",
"@sweetalert2/ngx-sweetalert2": "^5.1.0",
"angular-svg-round-progressbar": "^3.0.1",
"angular-user-idle": "^2.2.1",
"bootstrap": "^4.1.3",
"chart.js": "^2.8.0",
"core-js": "^2.5.4",
"file-saver": "^2.0.0",
"font-awesome": "^4.7.0",
"gsap": "^2.0.2",
"guid-typescript": "^1.0.9",
"hammerjs": "^2.0.8",
"imports-loader": "^0.8.0",
"jquery": "^3.3.1",
"lodash": "^4.17.11",
"moment": "^2.22.2",
"ng-circle-progress": "^1.5.1",
"ngrx-store-logger": "^0.2.2",
"ngx-bootstrap": "^3.2.0",
"ngx-cookie-service": "^2.1.0",
"ngx-toastr": "^9.1.0",
"node-sass": "^4.9.0",
"popper.js": "^1.14.3",
"primeicons": "^1.0.0-beta.10",
"primeng": "^6.0.2",
"rxjs": "^6.0.0",
"string": "^3.3.3",
"sweetalert2": "^8.13.6",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.7.0",
"@angular/cli": "~6.1.1",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@ngrx/schematics": "^6.1.0",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/lodash": "^4.14.116",
"@types/node": "~8.9.4",
"chai": "^4.1.2",
"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": "~2.7.2"
}
}
我的tsconfig.json是
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types",
"node",
"greensock"
],
"lib": [
"es2017",
"dom"
]
}
}
这个问题对我来说越来越重要了。请有人尝试查看是否存在我没有看到的任何问题检查服务是否存在循环依赖项。由于angular无法解决依赖关系,您很可能会遇到这样的问题。通常它在控制台中输出警告
如果存在包装器,另一个原因可能与不正确的构造函数引用有关。尽量避免索引文件,直接导入。索引文件也会导致角度方面的问题 您的项目中是否存在循环依赖项?可能是。我不是唯一一个在这个项目上工作的人。为什么你要告诉我?这是暂时的还是持续的错误?我可以在不使用--prod标志的情况下构建项目。当我添加标志时,我有这些错误,因此它将使用--prod标志保持不变。检查构造函数中的base.service中发送了什么,并检查它们是否是同一模块的一部分。正确。我在angular.json中找到了showcorculardependices:false,因此我将其设置为true,angular向我显示了许多关于循环依赖性的警告。你认为问题出在哪里?在循环依赖项中检测到警告:src\app\shared\services\index.ts->src\app\shared\services\garbagecollector.service.ts->src\app\shared\services\index.ts这似乎就是出现此类问题的原因。尝试直接使用完整路径导入BaseService中的服务,而不使用index.ts文件。