Angular 4 错误 : There are multiple modules with names that only differ in casing

标签 angular

在执行 ng serve 命令后,我的 Angular 4 项目出现以下错误。

./src/app/Utils/config.service.ts There are multiple modules with names that only differ in casing. This can lead to unexpected behavior when compiling on a filesystem with other case-semantic. Use equal casing. Compare these module identifiers: * D:\ANGULAR\siteprice.org\node_modules\@ngtools\webpack\src\index.js!D:\ANGULAR\siteprice.org\src\app\Utils\config.service.ts Used by 1 module(s), i. e. D:\ANGULAR\siteprice.org\node_modules\@ngtools\webpack\src\index.js!D:\ANGULAR\siteprice.org\src\app\utils\email.service.ts * D:\ANGULAR\siteprice.org\node_modules\@ngtools\webpack\src\index.js!D:\ANGULAR\siteprice.org\src\app\utils\config.service.ts Used by 2 module(s), i. e. D:\ANGULAR\siteprice.org\node_modules\@ngtools\webpack\src\index.js!D:\ANGULAR\siteprice.org\src\app\app.module.ts

config.service.ts 文件:

import { Injectable } from '@angular/core';

@Injectable()
export class ConfigService {

  _apiURI : string;

  constructor() {
      this._apiURI = 'http://www.example.com/xyz/api/';
    }

    getApiURI() {
        return this._apiURI;
    }

    getApiHost() {
        return this._apiURI.replace('api/','');
    }

}

email.service.ts:

import { Injectable } from '@angular/core';
import { Http, Response, Headers } from '@angular/http';
import {Observable} from 'rxjs';
import 'rxjs/add/operator/map';
import { ConfigService } from '../Utils/config.service';
import { Email } from '../Models/email';

@Injectable()
export class EmailService {

  apiRoot: string = '';

  constructor(private http: Http, private configService: ConfigService) { 
    this.apiRoot = configService.getApiURI();
  }

我检查了服务名称的大小写,它们是正确的。

最佳答案

我发现了这个问题,我认为它可能是 CLI 中的错误。

Utils 文件夹名称应为 utils。所以第一个字母是小写的。 我的 windows 目录中的 utils 文件夹是用小写字母创建的。 所以我改变了这个:

import { ConfigService } from '../Utils/config.service';

到:

import { ConfigService } from '../utils/config.service';

编辑:

看起来这是一个已知问题,建议的解决方案之一是在 Windows 中使用 kebap case 文件和文件夹名称。

https://github.com/AngularClass/angular-starter/issues/926

关于 Angular 4 错误 : There are multiple modules with names that only differ in casing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45444608/

相关文章:

javascript - ES6/TS/Angular2 将 JSON 解析为 Date

javascript - Angular 与静态页面或组件? (成分太多?)

Angular2 dart 属性绑定(bind)未更新

angularjs - "Port 4200 is already in use"。杀死与 4200 相关的所有进程没有用。

angularjs - 我如何在 Http Observable 上使用 "Interval"或类似的?

javascript - Crbug/1173575,非 JS 模块文件已弃用。 chromewebdata/(索引)꞉5305 :9:5551

javascript - 使用 Mutation Observer 检测 dom 元素样式变化

javascript - @Input ngOnChanges 使用我传入的数组生成一个新的嵌套数组 - 我该如何避免这种情况?

angular - TS2416 : Property 'canActivate' in type 'MyGuard' is not assignable to the same property in base type 'CanActivate'

angular - 捕获从注入(inject)组件的服务发出的事件