angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Cannot find module 'angularfire2' when using Angular-CLI and RC.4

Open thehashrocket opened this issue 10 years ago • 58 comments

I'm using angular-cli with the lastest RC4 version of Angular.

I was following the steps here: https://github.com/angular/angularfire2/blob/master/docs/1-install-and-setup.md

But I had to make a few very small changes. For one, I'm installing AngularFire this way: npm install git+https://github.com/angular/angularfire2.git --save so that I have a version that is compatible with RC4.

Secondly, when doing the typings step I do this: typings install file:node_modules/firebase/firebase.d.ts --save --global && typings install because that's where the firebase.d.ts file is now it seems.

Next I do this:

var map = {
    'firebase': 'vendor/firebase/firebase.js',
    'angularfire2': 'vendor/angularfire2'
};
/** User packages configuration. */
var packages = {
    angularfire2: {
        defaultExtension: 'ts',
        main: 'angularfire2.ts'
    }
};

Where I use the .ts file because there isn't a .js file for angularfire2 in the node_modules/angularfire2 folder. Even in the source folder it's just .ts files.

So, once I get to step 7, and do this: import { FIREBASE_PROVIDERS, defaultFirebase } from 'angularfire2'; everything falls apart. I'm not sure why, it should work?

thehashrocket avatar Jul 31 '16 05:07 thehashrocket

updated system-config, committed code and pushed to github. so far no errors. getting closer to the moment of truth.

thehashrocket avatar Aug 01 '16 02:08 thehashrocket

go ahead and try to import angularfire

lexcaraig avatar Aug 01 '16 02:08 lexcaraig

Keep it served

lexcaraig avatar Aug 01 '16 02:08 lexcaraig

ok, I did step 7 and it worked. this really blows my mind. i don't get why it worked?

thehashrocket avatar Aug 01 '16 02:08 thehashrocket

I think its because you did not finished the installing of the modules. That's why its giving you the errors that you can't find modules. Haha.

lexcaraig avatar Aug 01 '16 02:08 lexcaraig

can someone explain how it was able to work even with the unmet peer dependency?

├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]

and

npm WARN [email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN [email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN [email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN [email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN [email protected] requires a peer of @angular/[email protected] but none was installed.

thehashrocket avatar Aug 01 '16 02:08 thehashrocket

so weird, and so annoying! lol. i worked on this since saturday afternoon. lol. :(

thehashrocket avatar Aug 01 '16 02:08 thehashrocket

Just ignore it for now, i think they will get this done in the next release. All of your concern for now are the real errors. lol. Happy Coding!

lexcaraig avatar Aug 01 '16 02:08 lexcaraig

thanks for you help @lexcaraig , if not for you, I probably wouldn't have just pushed through that error. Every time I hit it, I tried a work around to pull directly from their github instead. still not sure exactly why that wasn't working, but it's working now. i owe ya. :)

thehashrocket avatar Aug 01 '16 02:08 thehashrocket

I think its all about the completion of installing the modules. Haha. Sure! No worries! I'm glad to help. :)

lexcaraig avatar Aug 01 '16 02:08 lexcaraig

did your facebook login work?

thehashrocket avatar Aug 01 '16 02:08 thehashrocket

Yes, it is working on my account but haven't try it yet with other accounts. I'm still working on some finishing touches before i finally deploy it. May lets close this thread and refer to my issue instead. #398

lexcaraig avatar Aug 01 '16 02:08 lexcaraig

@thehashrocket : Could you please publish your system-config.ts and your main.ts.

Would be great.

Jorg71 avatar Aug 16 '16 06:08 Jorg71

Sure, no problem:

main.ts:

import { bootstrap } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import {disableDeprecatedForms, provideForms} from '@angular/forms';
import { AppComponent, environment } from './app/';
import { APP_ROUTER_PROVIDERS } from './app/app.routes';
import {FIREBASE_PROVIDERS,
  defaultFirebase,
  AngularFire,
  AuthMethods,
  AuthProviders,
  firebaseAuthConfig,
  FirebaseListObservable
} from 'angularfire2';

if (environment.production) {
  enableProdMode();
}

bootstrap(AppComponent, [
  APP_ROUTER_PROVIDERS,
  FIREBASE_PROVIDERS,
  provideForms(),
  defaultFirebase({
    apiKey: "AIzaSyAMVh4NiFUBywVH0zQLxvsmtu1zt4AdUGo",
    authDomain: "angular-authentication.firebaseapp.com",
    databaseURL: "https://angular-authentication.firebaseio.com",
    storageBucket: "angular-authentication.appspot.com",
  }),
  firebaseAuthConfig({
    method: AuthMethods.Popup
  })
]);

system-config.ts:

"use strict";

// SystemJS configuration file, see links for more information
// https://github.com/systemjs/systemjs
// https://github.com/systemjs/systemjs/blob/master/docs/config-api.md

/***********************************************************************************************
 * User Configuration.
 **********************************************************************************************/
/** Map relative paths to URLs. */
const map: any = {
  'angularfire2': 'vendor/angularfire2',
  'firebase': 'vendor/firebase/firebase.js',
  'moment': 'vendor/moment/moment.js',
  'ng2-bootstrap': 'vendor/ng2-bootstrap'
};

/** User packages configuration. */
const packages: any = {
  angularfire2: {
    defaultExtension: 'js',
    main: 'angularfire2.js'
  },
  'moment':{
    format: 'cjs'
  },
  'ng2-bootstrap': {
    format: 'cjs',
    defaultExtension: 'js',
    main: 'ng2-bootstrap.js'
  }
};

////////////////////////////////////////////////////////////////////////////////////////////////
/***********************************************************************************************
 * Everything underneath this line is managed by the CLI.
 **********************************************************************************************/
const barrels: string[] = [
  // Angular specific barrels.
  '@angular/core',
  '@angular/common',
  '@angular/compiler',
  '@angular/forms',
  '@angular/http',
  '@angular/router',
  '@angular/platform-browser',
  '@angular/platform-browser-dynamic',

  // Thirdparty barrels.
  'rxjs',

  // App specific barrels.
  'app',
  'app/shared',
  'app/shared/roomly-navbar',
  'app/roomly-rooms',
  'app/roomly-home',
  /** @cli-barrel */
];

const cliSystemConfigPackages: any = {};
barrels.forEach((barrelName: string) => {
  cliSystemConfigPackages[barrelName] = { main: 'index' };
});

/** Type declaration for ambient System. */
declare var System: any;

// Apply the CLI SystemJS configuration.
System.config({
  map: {
    '@angular': 'vendor/@angular',
    'rxjs': 'vendor/rxjs',
    'main': 'main.js'
  },
  packages: cliSystemConfigPackages
});

// Apply the user's configuration.
System.config({ map, packages });

thehashrocket avatar Aug 16 '16 11:08 thehashrocket

Could you please make a screenshot of the content of the directory YOUR_PROJECT/vendor/angularfire2 please? I think some files are missing there...

I have the same issue... I tried the same things as you but unsuccessfully at the moment

phmaes avatar Aug 21 '16 16:08 phmaes

I tried on another machine with quite the same environment as for my first try (no previous installation of angular-cli, existing installation of angular2, typescript, etc) and it's successful...

The only different thing I made compared to your procedure and to my previous try is to update npm itself.

So: if needed: npm uninstall -g angular-cli

npm cache clean npm i -g npm npm install -g angular-cli@latest npm install -g typings

then I exactly followed the instructions here: https://github.com/angular/angularfire2/blob/master/docs/1-install-and-setup.md

ng new test-project cd test-project

npm install angularfire2 firebase --save I got some warnings and unmet peer dependencies

typings install file:node_modules/angularfire2/firebase3.d.ts --save --global && typings install

Ensure that these two entries are present in src/typings.d.ts "files": [ "node_modules/angularfire2/firebase3.d.ts", "typings/main.d.ts" ]

steps 4 to 10. And it works.

During my previous try, I've noticed that the files in the folder YOUR_PROJECT/vendor/angularfire2 weren't the right ones. Maybe something not well extracted or some missing files leading to a compilation aborted somehow, or a missing dependency.

Hope that helps!

phmaes avatar Aug 21 '16 21:08 phmaes

ANYONE HAVE A SOLUTION TO FIX THIS ERRORS: ERROR in src/app/app.module.ts(5,35): error TS2307: Cannot find module 'angular2-flash-messages/module'. src/app/app.module.ts(7,35): error TS2307: Cannot find module 'angularfire2'. src/app/app.module.ts(8,37): error TS2307: Cannot find module 'angularfire2/database'. src/app/app.module.ts(9,33): error TS2307: Cannot find module 'angularfire2/auth'. src/app/components/add-client/add-client.component.ts(2,38): error TS2307: Cannot find module 'angular2-flash-messages'. src/app/components/client-details/client-details.component.ts(3,38): error TS2307: Cannot find module 'angular2-flash-messages'. src/app/components/edit-client/edit-client.component.ts(3,38): error TS2307: Cannot find module 'angular2-flash-messages'. src/app/components/login/login.component.ts(2,38): error TS2307: Cannot find module 'angular2-flash-messages'. src/app/components/navbar/navbar.component.ts(2,38): error TS2307: Cannot find module 'angular2-flash-messages'. src/app/components/register/register.component.ts(2,38): error TS2307: Cannot find module 'angular2-flash-messages'. src/app/components/settings/settings.component.ts(4,38): error TS2307: Cannot find module 'angular2-flash-messages'. src/app/guards/auth.guard.ts(4,33): error TS2307: Cannot find module 'angularfire2/auth'. src/app/services/auth.service.ts(2,33): error TS2307: Cannot find module 'angularfire2/auth'. src/app/services/client.service.ts(2,87): error TS2307: Cannot find module 'angularfire2/database'.

jammey007 avatar Apr 03 '18 12:04 jammey007

@lexcaraig your solutions works with me ,thanks

safados avatar Dec 27 '18 09:12 safados