【问题标题】:Angular 4 error: There are multiple modules with names that only differ in casingAngular 4 错误:有多个模块的名称只是大小写不同
【发布时间】:2018-01-08 17:18:29
【问题描述】:

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

./src/app/Utils/config.service.ts 有多个模块的名称只是大小写不同。 在使用其他大小写语义的文件系统上编译时,这可能会导致意外行为。 使用相等的大小写。比较这些模块标识符: * D:\ANGULAR\siteprice.org\node_modules\@ngtools\webpack\src\index.js!D:\ANGULAR\siteprice.org\src\app\Utils\config.service.ts 由 1 个模块使用,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 由 2 个模块使用,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();
  }

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

【问题讨论】:

    标签: angular


    【解决方案1】:

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

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

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

    到:

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

    编辑:

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

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

    【讨论】:

      猜你喜欢
      • 2018-12-16
      • 2021-05-14
      • 1970-01-01
      • 2019-09-03
      • 1970-01-01
      • 2018-05-12
      • 2017-06-18
      • 2020-04-16
      • 2021-09-17
      相关资源
      最近更新 更多