特定角度库不使用prod设置构建

时间:2018-02-05 05:07:42

标签: angular angular5 ng2-date-countdown

我在我的应用程序中使用 ng2-date-countdown 库,用于显示某种剩余时间功能。

问题是,这适用于ng serve,但当我执行ng build --prod时,我收到错误。

  

Unexpected value 'CountDown in {projectDir}/node_modules/ng2-date-countdown/dist/countdown.d.ts' declared by the module 'AppModule in {projectDir}/src/app/app.module.ts'. Please add a @Pipe/@Directive/@component annotation.

我的发现

我查看了库的package.json文件,发现已经添加了以下依赖项。

"@angular/common": "5.1.2",
"@angular/compiler": "5.1.2",
"@angular/core": "5.1.2",
"rxjs": "5.5.6",

已存在于我的应用程序中,并且angular依赖项的版本更高。通过进一步的读数,我知道多个angular组件导致上述错误。此外,我认为版本不匹配也可能导致此问题。

我的尝试

我已经在存储库中提出了 issue ,但我刚才有一个建议说要用--aot=false构建它,据我所知应用程序的性能。

我还尝试通过删除package.json中的依赖项来分叉GitHub repo并使用自己的版本构建,但最终我一直在失败,因为我无法了解如何自行完成。

有人能指出我这个问题的正确方向吗?我还可以尝试解决此问题吗?

最后但并非最不重要,下面是我在我的应用程序中的依赖项。

"dependencies": {
    "@agm/core": "^1.0.0-beta.2",
    "@angular/animations": "^5.0.0",
    "@angular/cdk": "^5.0.0-rc0",
    "@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/material": "^5.0.0-rc0",
    "@angular/material-moment-adapter": "^5.0.3",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@types/lodash": "^4.14.65",
    "angular2-moment": "^1.7.1",
    "angularfire2": "^5.0.0-rc.4",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.4.1",
    "firebase": "^4.6.2",
    "hammerjs": "^2.0.8",
    "intl": "^1.2.5",
    "jquery": "^3.2.1",
    "ng2-cookies": "^1.0.12",
    "ng2-date-countdown": "0.0.5",
    "ng2-slim-loading-bar": "^4.0.0",
    "ng2-validation": "^4.2.0",
    "ngx-pagination": "^3.0.0",
    "ngx-slick": "^0.1.3",
    "razorpay": "^1.6.1",
    "reflect-metadata": "^0.1.12",
    "rxjs": "^5.5.2",
    "sweetalert2": "^7.3.0",
    "web-animations-js": "^2.3.1",
    "zone.js": "^0.8.14"
},
"devDependencies": {
    "@angular/cli": "^1.5.4",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/jquery": "^2.0.47",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.2.0",
    "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"
}

修改

app.module.ts我的Countdown

的特定代码下方
import {CountDown} from "ng2-date-countdown";

@NgModule({
    imports:[....], //all other imports
    declarations: [
       AppComponent,
       ..........
       Countdown
    ]
})

1 个答案:

答案 0 :(得分:0)

我也有同样的问题,最好的解决方案是不要使用ng2-date-countdown作为库组件。只需复制" countdown.ts" ," countdown.scss"和" countdown.html"来自" / node_modules / ng2-date-countdown / src"并将其粘贴到您的应用程序而不是导入复制的组件



import {CountDown} from "./components/countDown/countdown";




import {CountDown} from "./components/countDown/countdown";