在执行 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 文件和文件夹名称。
关于 Angular 4 错误 : There are multiple modules with names that only differ in casing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45444608/