Ionic2: Bundle failed: Could not resolve '../providers/data' from ...app.module.ts

Hi,
Working with Ionic2 RC.1 and creating a fresh app using the tabs template.

The app works until I generate a provider. The moment I add it, I get the error

[16:40:11]  lint finished in 1.41 s 
[16:40:13]  transpile finished in 2.93 s 
[16:40:13]  bundle started ... 
[16:40:13]  copy finished in 2.98 s 
[16:40:18]  bundle failed: Could not resolve '../providers/data' from /Users/.../src/app/app.module.ts 
[16:40:18]  watch ready in 8.13 s 
Running live reload server: http://localhost:35729
Watching: www/**/*, !www/lib/**/*, !www/**/*.map
√ Running dev server:  http://localhost:8100
Ionic server commands, enter:
  restart or r to restart the client app from the root
  goto or g and a url to have the app navigate to the given url
  consolelogs or c to enable/disable console log output
  serverlogs or s to enable/disable server log output
  quit or q to shutdown the server and exit

My app.module.ts

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { AboutPage } from '../pages/about/about';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';

import { Data } from '../providers/data';

@NgModule({
  declarations: [
    MyApp,
    AboutPage,
    ContactPage,
    HomePage,
    TabsPage
  ],
  imports: [
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    AboutPage,
    ContactPage,
    HomePage,
    TabsPage
  ],
  providers: [Data]
})
export class AppModule {}

Any ideas ?

1 Like

Apparently ionic couldn’t find your file.
Is it data.ts directly in the providers directory ?
Or data.ts in directory “data” in directory “providers” ?
What does your app structure looks like ?

Generally, you should have somtehing like that : import { Data } from '../../providers/data/data';

@elvis_gn If the path ../providers/data is a folder (with an index.ts file inside, exporting classes; that is, a barrel) you can try to import from ../providers/data/index. At least this is what happened to me when I updated from RC0 to RC1, and I had to change imports in hundreds of files T-T (the good thing is that it worked).

If this is not your case, maybe your path is wrong in app.module.ts, like @mvrc pointed out. Do you have the file /Users/.../src/providers/data.ts?

UPDATED

If your problem is with barrels (you have an index.ts file inside your folder), it is now fixed. Just update ionic-app-scripts to version 0.0.36:

npm install @ionic/app-scripts@latest --save-dev

Related issue:

@lucasbasquerotto: Thanks, the update worked.