Angular 6 has numerous modules that have similar names but vary only in their letter casing

After running ng serve, I encountered an error that has me stumped. Everything was working fine with the new service I created until suddenly it all crashed :( I tried troubleshooting everything possible but to no avail. Even Google didn't provide any solutions :(

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.

Below is my app.module:

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 { }

And here is my booking service.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 response
  private extractData(res: Response) {
    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) {
      console.error('An error occurred:', error.error.message);
    } else {
      console.error(
        `Backend returned code ${error.status}, ` +
        `body was: ${error.error}`);
    }
    return throwError('Something bad happened; please try again later.');
  }
}

Can anyone offer insights or suggestions on what might be wrong with my codes? Any help would be greatly appreciated. Thank you.

Answer №1

Typically, this issue arises from a small typo.

Be sure to review all your components, services, and modules. If you are importing something like 'smallcase', double check it.

In this particular scenario, it seems that you have forgotten to import Rxjs.

import { Observable } from 'Rxjs/Observable';

Answer №2

Your code is not correctly importing rxjs packages. Make the following changes for it to work properly:

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

Answer №3

The problem I encountered was due to mistakenly using a capitalized file name in one of my imports.

Here is the incorrect import statement:

import { UserService } from '../../Services/User.service';

And here is the correct import statement:

import { UserService } from '../../Services/user.service';

Make sure to match the case sensitivity of file names when importing modules.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Positioning the search bar to the left with react-bootstrap-table

Is there a way to move the search bar of react-bootstrap-table to the left instead of keeping it on the right? You can see an example here, at the bottom of the page: I know that you can create a custom search panel and input, but that seems like a compl ...

Ensure that the landing image remains in place and covered as I continue scrolling

Can someone help me figure out how to adjust my landing page so that as I scroll, the content covers the background image? I'm looking for a similar effect to what's seen on this website: ...

What causes the offsetWidth attribute to be zero in an array of elements within the DOM?

I am encountering an issue with a script that sets widths for certain elements in the Dom. Specifically, when I use the code var elements = document.querySelectorAll("p.caption"), the first 12 elements display the correct offsetWidth, but the remaining hal ...

What is the best way to utilize Object.keys() for working with nested objects?

When working with nested objects, I am trying to access the properties using Object.keys() and forEach(). However, I am encountering an issue when attempting to access the nested keys filteringState[item][el]. Is there a specific way to write a function f ...

Conceal information on-the-fly using React

I am seeking a way to dynamically hide irrelevant items based on their tags. This functionality should only be applied to tags with a "taglevel" higher than 1. For instance, if I select the tag "books," only the tags "adventure" and "classic" should be d ...

Error: ajax is not defined and needs to be declared (repeated twice)

Currently, I have a form that requires processing using Ajax. <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script> <div class="column1"> <form class="form box" action="javascript:networkCheck();" ...

Adjusting the slider with jQuery and CSS to extend beyond 100% while remaining within the div boundaries

Currently, I'm working on customizing a jQuery slider. My goal is to achieve the same functionality as the jQuery UI slider where you can set a max value like "2500" and the slider will smoothly adjust without going outside of the specified div or scr ...

Loop through the JSON data to generate clickable links in the innerHTML

I've been searching through various resources for a solution to the issue I'm facing. My goal is to iterate through a JSON object and extract all the ids and corresponding dates from each top_worst section. The structure of the JSON data is as fo ...

How come the rotation of my Three.js mesh gets thrown off when I adjust the scale?

I managed to achieve my goal of rotating a sphere around the x and y axes using the following code: // Update ball rotation. var tempMat = new THREE.Matrix4(); tempMat.makeRotationAxis(new THREE.Vector3(0,1,0), stepX/ballRadius); tempMat.multiplySelf(ball ...

Incorporating MongoDB collection elements into a Discord embed display

I am trying to include my collection of documents in an embed using MongoDB's ForEach function. However, I have noticed that when attempting to add a field to the embed within the forEach loop, it appears that the code sends the message first and the ...

AngularJS - Retaining the initial value without submitting

On the left side, I have a list of users with corresponding details displayed on the right. The form handles the details on the right using inputs with ng-model. Whenever I click on a user from the left section, the selected user changes and the model auto ...

Issues with sample AJAX request functionality

Attempting to learn AJAX with a basic call. I've got a .txt file in the same directory as my HTML file. Can someone pinpoint where I may have gone wrong? Appreciate any help. <html> <head> <script type="text/javascript"> ...

Scrapy encountering a challenge with retrieving empty pages containing JavaScript code

Every time I try to use scrapy to scrape or view (or similar pages on that site), all I get is a blank page. The page source just shows hidden javascript code, nothing else. I've experimented with different user agents, proxies, settings, and more ( ...

Once the image is loaded, cropped, and displayed on the canvas, what is the best way to implement image rotation functionality for the user before converting it to base64?

My process involves cropping images to a square shape and drawing them onto a canvas. if(img.height >= img.width) { ctx.drawImage(img, 0, 0, 110, 110 * img.height / img.width); } else { ctx.drawImage(img, 0 , 0, 110 * img.width ...

Implement a T3 App Redirect in a TRPC middleware for unsigned users

Is there a way to implement a server-side redirect if a user who is signed in has not finished filling out their profile page? const enforceUserIsAuthed = t.middleware(({ ctx, next }) => { if (!ctx.session || !ctx.session.user) { throw new TRPCE ...

CSS Challenge: How to crop an image without using its parent container directly

I'm currently facing a complex CSS challenge that I can't seem to solve. I want to create an image controller (two-by-two layout on two lines) that can display: The top-left image in full size, The top-right with horizontal scrolling, The botto ...

Are you experiencing issues with running unit tests in VSTS using angular-cli?

I have successfully created a project using angular-cli on my local system, and the unit tests are running fine. However, when I try to run the tests as part of the build process in VSTS, I encounter the following error: > ng test --cc Your global Ang ...

How to use jQuery to remove the last element from an array when the back button

Currently encountering an issue with removing the last element from an array when a back button is clicked. The console is displaying the correct elements in the array, but it seems that the array.slice function is not working as expected, and I'm str ...

Angular not updating the values in real time

First and foremost, I am utilizing socket.io to emit data. Data is emitted upon connection (so the website does not appear blank) as well as when certain events occur. Upon initial connection or page refresh, everything updates and functions smoothly. Howe ...

JavaScript error: Attempting to access 'filter' property of undefined variable

I am facing an issue with the filter function in JavaScript not working as expected. I suspect it might be due to the API taking a long time to respond. This is my code: const getDataAll = () =>{ const [machines, setMachines] = useState([]) co ...