【问题标题】:error TS2687: All declarations of 'observable' must have identical modifiers错误 TS2687:“可观察”的所有声明必须具有相同的修饰符
【发布时间】:2018-11-11 08:46:51
【问题描述】:

我有一个 Angualr 6 项目,我正在尝试运行以下命令 npm run build。下面的错误信息是如何出现的。

ERROR in node_modules/rxjs/internal/symbol/observable.d.ts(4,9): error TS2687: All declarations of 'observable' must have identical modifiers.

node_modules/@types/node/index.d.ts(167,14): error TS2687: All declarations of 'observable' must have identical modifiers.

角度版本

  Angular CLI: 6.0.0
    Node: 9.8.0
    OS: darwin x64
    Angular: 6.0.0
    ... animations, cdk, cli, common, compiler, compiler-cli, core
    ... forms, http, language-service, material, platform-browser
    ... platform-browser-dynamic, router

    Package                           Version
    -----------------------------------------------------------
    @angular-devkit/architect         0.6.0
    @angular-devkit/build-angular     0.6.0
    @angular-devkit/build-optimizer   0.6.0
    @angular-devkit/core              0.6.0
    @angular-devkit/schematics        0.6.0 (cli-only)
    @angular/flex-layout              6.0.0-beta.15
    @ngtools/webpack                  6.0.0
    @schematics/angular               0.6.0 (cli-only)
    @schematics/update                0.6.0
    rxjs                              6.1.0
    typescript                        2.7.2
    webpack                           4.6.0

忘了说只发生在我的 docker 镜像中。

docker build -t $IMG --build-arg env=production .

# Stage 0 - Pre-requisite: Based On Node.js to BUILD and compile Demo Angular App.

FROM node:8.11.2 as node

WORKDIR /app

COPY package.json /app/

RUN npm install

COPY ./ /app/

ARG env

RUN npm run build -- --configuration $env

# Stage 1 - Based On Nginx to have ONLY a compiled and PRODUCTION ready build.

FROM nginx:1.14

COPY --from=node /app/dist/ /usr/share/nginx/html

COPY ./nginx-custom.conf /etc/nginx/conf.d/default.conf

【问题讨论】:

    标签: angular typescript docker angular-cli


    【解决方案1】:

    低版本的节点也有同样的问题。

    解决了什么问题:

    • 转到有问题的observable.d.ts,在我的情况下是: node_modules/angular-datatables/node_modules/rxjs/internal/symbol/observable.d.ts

    • 改变:

    declare global {
        interface SymbolConstructor {
            readonly observable: symbol;
        }
    }
    

    到:

    declare global {
        interface SymbolConstructor {
            observable: symbol;
        }
    }
    

    我猜反之亦然。

    【讨论】:

      【解决方案2】:

      将@types/node 更新到 10.3.0 后遇到同样的问题。降级到 10.1.4 版后,一切都恢复正常了。我认为必须更新 rxjs 才能使用最新的 @types/node 版本。所以目前,只需使用旧版本:

      npm install @types/node@10.1.4
      

      更新:RxJS 的修复已经完成 -> https://github.com/ReactiveX/rxjs/pull/3773 。现在他们只需合并更改并发布新版本。

      【讨论】:

      • 我忘了说这只发生在我的 docker 镜像中。在当地它很好。昨天还不错,不知道今天有什么变化。
      • 刚刚救了我们。可以确认这在 AWS CodeBuild 中失败,但在本地成功。将 @types/node 设置为 10.1.4 可以解决所有问题。
      • 是的,它奏效了。但我必须先停止并重新启动我的服务器
      猜你喜欢
      • 2017-08-13
      • 2021-05-29
      • 2019-04-25
      • 1970-01-01
      • 2023-03-21
      • 2016-11-07
      • 1970-01-01
      • 2019-09-04
      • 2022-09-30
      相关资源
      最近更新 更多