You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 17.2.0引入ConnectionServiceModule遇NG6002错误求解决方案

解决ng-connection-service与Angular Ivy兼容性错误

问题描述

导入ConnectionServiceModule时触发以下编译错误:

Error: src/app/app.module.ts:39:5 - error NG6002: 'ConnectionServiceModule' does not appear to be an NgModule class.

39     ConnectionServiceModule
       ~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/ng-connection-service/lib/ng-connection-service.module.d.ts:1:22
    1 export declare class ConnectionServiceModule {
~~~~~~~~~~~~~~~~~~~~~~~
                           
This likely means that the library (ng-connection-service) which declares ConnectionServiceModule is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.

解决方法

  • 更新库至兼容版本

    1. 查看当前安装的库版本:
      npm list ng-connection-service
      
    2. 安装最新版本:
      npm install ng-connection-service@latest --save
      

    安装完成后重新编译项目,验证错误是否消失。如果仍有问题,查看库的官方文档或issue列表,确认是否已支持Angular Ivy。

  • 临时禁用Angular Ivy
    若暂时没有兼容版本,可在tsconfig.json中禁用Ivy编译器(仅作为临时方案,不推荐长期使用):

    {
      "compilerOptions": { ... },
      "angularCompilerOptions": {
        "enableIvy": false
      }
    }
    
  • 替换为兼容Ivy的替代方案
    可以基于浏览器原生API自行实现网络状态监听,示例代码如下:

    import { Injectable } from '@angular/core';
    import { Observable, fromEvent, merge, of } from 'rxjs';
    import { mapTo } from 'rxjs/operators';
    
    @Injectable({ providedIn: 'root' })
    export class ConnectionService {
      isOnline$: Observable<boolean>;
    
      constructor() {
        this.isOnline$ = merge(
          of(navigator.onLine),
          fromEvent(window, 'online').pipe(mapTo(true)),
          fromEvent(window, 'offline').pipe(mapTo(false))
        );
      }
    }
    

内容的提问来源于stack exchange,提问作者Prasanta Badatya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 11:03:14