Mubashar Abbas
Mubashar Abbas

Reputation: 5673

Ionic 2 import looks for js instead of ts file

I am new to ionic2 and following a tutorial on youtube.

I have created a service in my src/app/services/ called RedditService and it's file name is reddit.service.ts

And in app.component.ts file I am importing it like this:

import { RedditService } from './services/reddit.service';

When it builds I get an error:

Module build failed: Error: ENOENT: no such file or directory, open '/home/mubashar/code/js/ionic/ionreddit/src/app/services/reddit.service.js'

it is looks for reddit.service.js when it SHOULD BE looking for reddit.service.ts and that I think is the problem.

This is the tutorial I am following:

https://youtu.be/ilM8YorL_jI

Upvotes: 0

Views: 654

Answers (1)

sebaferreras
sebaferreras

Reputation: 44669

Please keep in mind that sometimes when adding new files (services or pages) the CLI may throw an error, but if you stop it and run ionic serve again you will see the real cause of that error.

UPDATE:

I restarted and now I am getting Uncaught (in promise): Error: No provider for Http! Error: No provider for Http! at injectionError

Providers have Http included by default, and in order to use Http in your app you will need to add the HttpModule to your app.module.ts:

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule, ErrorHandler } from '@angular/core'; 
import { HttpModule } from '@angular/http'; 

...   

imports: [
    BrowserModule,
    HttpModule,
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot()   ], 
...

Upvotes: 3

Related Questions