Cannot find name 'Firebase'

I just started a ionic 2 project with typescript, and im getting both theses errors:

ERROR in [default] /Users/rodrigoreal/Projects/rodrigo/myproject/app/app.ts:25:18
Cannot find name 'Firebase'.

ERROR in [default] /Users/rodrigoreal/Projects/rodrigo/myproject/node_modules/angular2/src/facade/promise.d.ts:1:9
Cannot re-export name that is not defined in the module.

In my index.html
<script src="lib/firebase/firebase.js"></script>

Anyone have any idea how to fix that?

To fix the first error you have to install the Firebase definitions - run this command:

typings install firebase --ambient --save

NOTE: If you don’t have typings installed then you have to install it first:

npm install typings -g

The second error is caused by incompatibility between TypeScript and Angular (see angular issue #6468, tl;dr: TypeScript 1.8 requires angular2 beta.7 or higher). Check in your package.json file which version of TypeScript is used (most probably 1.8+). This error will be resolved with the next Ionic2 release (beta.4) because the master is already updated to Angular2 beta.8.

2 Likes

@iignatov Thanks man, worked like charm.

How do I update my ionic2 app to the latest beta version?

To update to the latest Ionic 2 beta release:

npm install -g ionic@beta

If you already have project(s) started with an earlier release of Ionic 2 then you’ll have to update the project(s) as well (check the linked post for more details):

In such case, keep in mind that depending on how old release of Ionic 2 the project is using, you may hit a few (or many) breaking changes.

Ok great thanks iignatov - I will definitely make a copy of the project.

Cheers

Just to clarify, running this command:

npm install -g ionic@beta

is updating the Ionic CLI Version not the framework. So when you run ionic info in your project folder and get something similar to this:

Ionic Version: 2.0.0-beta.3
Ionic CLI Version: 2.0.0-beta.21

then run the above command, it will only update the Ionic CLI Version which is used to run the ionic commands i.e. ionic start, ionic serve, etc.

If you want to update your version of the framework, you can modify the package.json where it says ionic-angular to the version you want, and then run npm install in the project directory:

"ionic-angular": "2.0.0-beta.3",

More info on this here: http://ionicframework.com/docs/v2/resources/using-npm/

1 Like

@brandyshea thanks for the great clarification!

1 Like

@iignatov I am facing the same issue but i have fire base installed firebase@3.0.5
└── es6-promise

system information:

Cordova CLI: 6.1.1
Gulp version:  CLI version 3.9.1
Gulp local:   Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.10
Ionic CLI Version: 2.0.0-beta.25
Ionic App Lib Version: 2.0.0-beta.15
ios-deploy version: Not installed
ios-sim version: 5.0.8 
OS: Mac OS X El Capitan
Node Version: v4.4.3
Xcode version: Xcode 7.3.1 Build version 7D1014 
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/BPProduct/BPProduct.ts(26,8): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/BPProduct/newBPProduct.ts(35,9): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/BPProduct/newBPProduct.ts(37,36): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/BPProduct/newBPProduct.ts(41,17): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/Listing/listingPage.ts(23,9): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/NewBP/newBP.ts(44,13): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/NewBP/newBP.ts(74,16): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/NewBP/newBP.ts(122,9): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/NewBP/newBP.ts(127,35): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/NewBP/newBP.ts(130,17): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/NewBP/newBP.ts(151,8): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/home/home.ts(51,9): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/list/list.ts(67,9): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/order/create.ts(61,9): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/order/create.ts(72,31): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/order/create.ts(104,13): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/order/newProduct.ts(26,8): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/order/view.ts(37,9): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/order/view.ts(62,13): Error TS2304: Cannot find name 'firebase'.
TypeScript error: /Users/yokesh/3ssdmobile/app/pages/order/view.ts(89,39): Error TS2304: Cannot find name 'firebase'.
TypeScript error: app/app.ts(33,9): Error TS2304: Cannot find name 'firebase'.
TypeScript error: typings/globals/firebase/index.d.ts(323,2): Error TS2300: Duplicate identifier 'export='.
TypeScript error: typings/modules/firebase/index.d.ts(509,1): Error TS2300: Duplicate identifier 'export='.

i get this err when i try to do e2e, I followed this link http://lathonez.github.io/2016/ionic-2-e2e-testing/

i get this only after installing those dependency

running your command I get:

typings ERR! deprecated The "ambient" flag is deprecated. Please use "global" instead

and running with global gives:

[cos@localhost app1]$ typings install firebase --global --save
typings ERR! message Attempted to compile "firebase" as a global module, but it looks like an external module. You'll need to remove the global option to continue.

typings ERR! cwd /home/cos/app1
typings ERR! system Linux 3.10.0-327.el7.x86_64
typings ERR! command "/home/cos/.nvm/versions/node/v6.3.1/bin/node" "/home/cos/.nvm/versions/node/v6.3.1/bin/typings" "install" "firebase" "--global" "--save"
typings ERR! node -v v6.3.1
typings ERR! typings -v 1.3.2

typings ERR! If you need help, you may report this error at:
typings ERR!   <https://github.com/typings/typings/issues>

I will try without the global option but shudder to think of the repercussions down the road for such a daring venture (on another note…after a long enduring struggle with node and permissions - why dont you guys offer NOOBs the suggestion to install nvm instead of the ridiculous way node installs ? - had this struggle with node while playing around with docker too)

Hi I am new to Ionic2, (and Ionic in general), and i am facing the same issue, i run the command
npm install typings -g
and the other one
typings install firebase --save but still getting the same error Cannot find name 'firebase' i did those things under my working folder, is there something i can do to get a workaround or did i miss something there?

Thanks in advance

Well, typings introduced some breaking changes with the release of v1.0.

According to the typings README the new way to install definitions is:

# Install typings from a particular source (use `<source>~<name>` or `--source <source>`).
typings install dt~firebase --global --save
typings install firebase --source dt --global --save

Check out the following Github comment for more details:

You might be running typings 1.0, which introduced some breaking changes. Try:
$ typings install dt~firebase --global --save
You may also need to update your tsconfig.json from … to …

Hi, i’m just adding firebase through the js method on their site (adding the code to the index.html). I’ve tried updating the typings as stated on the typings git but am still getting TS2304 errors:

app/login/login.component.ts(26,9): error TS2304: Cannot find name 'firebase'.
app/login/login.component.ts(51,9): error TS2304: Cannot find name 'firebase'.
app/login/login.component.ts(60,13): error TS2304: Cannot find name 'firebase'.
app/login/login.component.ts(63,56): error TS2304: Cannot find name 'firebase'.
app/app.component.ts(16,9): error TS2304: Cannot find name 'firebase'.

It also underlines each call refernece to firebase in my components. Do i need to import firebase in my components??
Thanks

It’s hard to say without seeing your code and knowing which version of Firebase are you using, therefore I’ll recommend you to check out the following resources:

1 Like

you should edit in last typings/module/firebase/index.ts
export your firebase like this…


namespace firebase.storage {
interface UploadTaskSnapshot {
bytesTransferred: number;
downloadURL: string;
metadata: firebase.storage.FullMetadata;
ref: firebase.storage.Reference;
state: firebase.storage.TaskState;
task: firebase.storage.UploadTask;
totalBytes: number;
}
}

export = firebase;
}

and edit your last lines of node_modules/firebase/firebase.d.ts

interface UploadTaskSnapshot {
bytesTransferred: number;
downloadURL: string|null;
metadata: firebase.storage.FullMetadata;
ref: firebase.storage.Reference;
state: firebase.storage.TaskState;
task: firebase.storage.UploadTask;
totalBytes: number;
}
}

export = firebase;

I don’t think recommending people edit things under node_modules is a good idea. npm will blow away your changes time and again. This thread is also pretty irrelevant since ionic-native >=2.3.0 which added a Firebase plugin.