javascript - Angular 6 : There are multiple modules with names that only differ in casing

标签 javascript angular typescript webpack

运行 ngserve 时出现以下错误,我刚刚创建了新服务,它工作正常,但突然一切都崩溃了:(, 我尝试了一切,但无法完成工作,谷歌也没有帮助:(

WARNING in ./src/app/Booking.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:
* C:\Users\Bonge\Documents\Projects\bookingapp\booking-client\node_modules\@ngtools\webpack\src\index.js!C:\Users\Bonge\Documents\Projects\bookingapp\booking-client\src\app\Booking.service.ts
    Used by 2 module(s), i. e.
    C:\Users\Bonge\Documents\Projects\bookingapp\booking-client\node_modules\@ngtools\webpack\src\index.js!C:\Users\Bonge\Documents\Projects\bookingapp\booking-client\src\app\about\about.component.ts
* C:\Users\Bonge\Documents\Projects\bookingapp\booking-client\node_modules\@ngtools\webpack\src\index.js!C:\Users\Bonge\Documents\Projects\bookingapp\booking-client\src\app\booking.service.ts
    Used by 2 module(s), i. e.
    C:\Users\Bonge\Documents\Projects\bookingapp\booking-client\node_modules\@ngtools\webpack\src\index.js!C:\Users\Bonge\Documents\Projects\bookingapp\booking-client\src\app\app.module.ts
i 「wdm」: Compiled with warnings.

这是我的应用程序模块

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { JsonpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
import { FlashMessagesModule } from 'angular2-flash-messages';
import { ReactiveFormsModule } from '@angular/forms';
import { AboutComponent } from './about/about.component';
import {CalendarModule} from 'primeng/calendar';
import { BookingService } from './booking.service';
@NgModule({
  declarations: [
    AppComponent,
    AboutComponent
  ],
  imports: [
    BrowserModule,
    JsonpModule,
    CalendarModule,
    ReactiveFormsModule,
    FormsModule,
    HttpClientModule,
    FlashMessagesModule.forRoot(),
    RouterModule.forRoot([
      { path: 'about', component: AboutComponent }
    ]),
  ],
  providers: [BookingService],
  bootstrap: [AppComponent]
})
export class AppModule { }

这是我的预订服务。ts

import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { catchError, map } from 'rxjs/operators';
import { Observable, throwError } from 'rxjs';
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';

const httpOptions = {
  headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
const apiUrl = 'http://localhost:8000/booking';

@Injectable({
  providedIn: 'root'
})
export class BookingService {
  bookingsUrl = '/booking';
  addBookingsUrl = '/bookings';
  constructor(private http: HttpClient) { }
  // function to extract data from rensponse
  private extractData(res: Response) {
    // tslint:disable-next-line:prefer-const
    let body = res;
    return body || {};
  }

  // Return Booking
  getBookings(id: string): Observable<any> {
    const url = `${apiUrl + this.bookingsUrl}/${id}`;
    return this.http.get(url, httpOptions).pipe(
      map(this.extractData),
      catchError(this.handleError));
  }
  // Adds Booking
  addBooking(date, email, city, hotel): Observable<any> {
    const uri = `${apiUrl + this.addBookingsUrl}`;
    const obj = {
      date: date,
      email: email,
      city: city,
      hotel: hotel

    };
    return this.http.post(uri, obj);
  }
  // Errors Handler
  private handleError(error: HttpErrorResponse) {
    if (error.error instanceof ErrorEvent) {
      // A client-side or network error occurred. Handle it accordingly.
      console.error('An error occurred:', error.error.message);
    } else {
      // The backend returned an unsuccessful response code.
      // The response body may contain clues as to what went wrong,
      console.error(
        `Backend returned code ${error.status}, ` +
        `body was: ${error.error}`);
    }
    // return an observable with a user-facing error message
    return throwError('Something bad happened; please try again later.');
  }
}

我的代码有什么问题吗?任何想法或建议将不胜感激,谢谢

最佳答案

这通常是由于微小的拼写错误造成的。

检查您的所有组件、服务、模块,如果您像 import 'smallcase'

在您的情况下,您尚未导入Rxjs

import { Observable } from 'Rxjs/Observable';

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

相关文章:

javascript - 来自函数的一次异步执行的数据与该函数的另一次执行混合

Angular 2 : create and destroy timer

css - 为什么子组件样式会被全局 css 覆盖?

javascript - 当绑定(bind)到 typescript 中的输入时,KnockoutObservable<number> 返回字符串

javascript - NestJs 基于用户属性和策略的 CASL 授权守卫

typescript - 使用 Typescript 访问 Vue3 中的商店

javascript - 为什么 jQuery 的 Ajax AutoComplete 不起作用?

javascript - Ext JS - Store 与 JsonStore

javascript - 在表格内设置分页符

javascript - Firebase 和 auth 属性在 Ionic 和 Firebase 中不存在