【问题标题】:Using ng2- libraries in --prod build throws "Unexpected value... Please add a @Pipe/@Directive/@Component annotation"在 --prod build 中使用 ng2- 库会引发“意外值...请添加 @Pipe/@Directive/@Component 注释”
【发布时间】:2018-02-07 08:12:16
【问题描述】:

我在 Angular CLI v1.6.3 上运行 Angular 5 应用程序。我需要使用一个名为ng2-img-map 的库,因为它是解决其中一个问题的唯一有效解决方案。但是,当我运行ng build --prod 时,它会抛出。

ERROR in : Unexpected value 'ImgMapComponent in C:/Users/.../node_modules/ng2-img-map/ng2-img-map.d.ts' declared by the module 'AppModule in C:/Users/.../src/app/app.module.ts'. Please add a @Pipe/@Directive/@Component annotation.

当我只运行 ng build 时,它可以正常工作。

我注意到在一年左右没有更新的其他 ng2- 库中会发生这种情况。我只是使用其他东西,但是我没有这个选项/时间。

有什么办法可以修复/绕过这个问题并在--prod 模式下使用库?

【问题讨论】:

  • 你在使用 webpack 吗?
  • @LucaTacagni 他没有,angular-cli 有
  • 移除aot,ng build --prod --aot=false
  • @DanielNetzer 我认为问题在于 OP 想要拥有所有好的东西 + 使用他喜欢的库。问题是 AOT 是如此严格(而且它是好的),以至于过去没有/没有针对 AOT 的所有库很可能不会通过它的检查。 OP:你不会在这里找到任何选项。调整库或禁用产品构建的某些部分
  • 正如我所说,他可以从他的编译中删除 AOT 属性,但应用程序的大小会大得多,而且确实很多 lib 都是无用的导致 AOT 不兼容的原因。

标签: angular angular-cli angular5


【解决方案1】:

尝试修改您的 tsconfig.json 添加声明:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ],
    "declaration": [
      "pathToYourFile.d.ts"
    ]
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-27
    • 2021-08-15
    • 2019-04-24
    • 2018-03-14
    • 1970-01-01
    • 1970-01-01
    • 2017-12-23
    • 2018-12-29
    相关资源
    最近更新 更多