TypeScript icon, indicating that this package has built-in type declarations

3.2.4 • Public • Published


A plugin that allows you to add Firebase Crashlytics to your NativeScript app.

Note: Use this plugin with the @nativescript/firebase-core plugin to initialize Firebase.

Crashlytics helps you to collect analytics and details about crashes and errors that occur in your app. It does this through three aspects:

  • Logs: Log events in your app to be sent with the crash report for context when your app crashes.
  • Crash reports: Every crash is automatically turned into a crash report and sent.
  • Stack traces: Even when an error is caught and your app recovers, the JavaScript stack trace can still be sent.



Install the plugin by running the following command in the root directory of your project.

npm install @nativescript/firebase-crashlytics

Use @nativescript/firebase-crashlytics

Log a crash context

Use the log method throughout your app to accumulate extra context for possible crashes that can happen.

import { firebase } from '@nativescript/firebase-core';
import '@nativescript/firebase-crashlytics'; // only needs to be imported 1x

const crashlytics = firebase().crashlytics();
crashlytics.log('User signed in.');

Set crash attributes for more context data

For additional context, Crashlytics also offers various methods to set attributes for the crash report.

  • To set a single attribute, call the setAttribute method passing it the attribute name as the first argument and its value as the second argument.
import { firebase } from '@nativescript/firebase-core';
import '@nativescript/firebase-crashlytics'; // only needs to be imported 1x

const crashlytics = firebase().crashlytics();

crashlytics().setAttribute('credits', String(user.credits));
  • To set multiple attributes at once, call the setAttributes method with an object containing the attributes.
import { firebase } from '@nativescript/firebase-core';
import '@nativescript/firebase-crashlytics'; // only needs to be imported 1x

const crashlytics = firebase().crashlytics();

  role: 'admin',
  followers: '13',
  email: user.email,
  username: user.username,

You can use set methods to set predefined attributes, but you can also set your own custom attributes.

  • You can also set the user ID. To do that call the setUserId method on firebase().crashlytics()
import { firebase } from '@nativescript/firebase-core';
import '@nativescript/firebase-crashlytics'; // only needs to be imported 1x

const crashlytics = firebase().crashlytics();


Test crashlytics

To test Crashlytics for your app, call the crash method to force a crash and in Firebase Console, see if the crash is logged.


Report errors manually

Crashlytics also supports sending JavaScript stack traces to the Firebase console. This can be used in any situation where an error occurs but is caught by your code to recover gracefully.

To send a stack trace, pass a JavaScript Error to the recordError method.

Even if you catch unexpected errors, for your app to recover and behave smoothly you can still report them through Crashlytics using the recordError method. This will also provide you with the associated stack trace.

import { firebase } from '@nativescript/firebase-core';

firebase().crashlytics().log('Updating user count.');

try {
  if (users) {
} catch (error) {

Manually enable or disable crashlytics collection

As Crashlytics will be sending certain information regarding the user, users may want to opt out of the crash reporting. To disable crashlytics collection, call the setCrashlyticsCollectionEnabled method on firebase().crashlytics() passing it false This can be done throughout the app with a simple method call to setCrashlyticsCollectionEnabled:

import { firebase } from '@nativescript/firebase-core';




The Crashlytics class has the following members.


Property Type Description
ios readonly
android readonly
app FirebaseApp readonly


Method Returns Description
checkForUnsentReports() Promise<boolean>
crash() void
deleteUnsentReports() void
didCrashOnPreviousExecution() boolean
log(message: string) void
recordError(error: any) void
sendUnsentReports() void
setAttribute(name: string, value: string | number | boolean) void
setAttributes(attributes: { [key: string]: string | number | boolean }) void
setCrashlyticsCollectionEnabled(enabled: boolean) void
setUserId(userId: string) void


Apache License Version 2.0

Package Sidebar


npm i @nativescript/firebase-crashlytics

Weekly Downloads






Unpacked Size

247 kB

Total Files


Last publish


  • nativescript-user
  • tns-bot
  • lini
  • tachev
  • rosen-vladimirov
  • stoskov
  • rosen_vladimirov
  • walkerrunpdx
  • bradmartin
  • davecoffin
  • rigor789
  • nativescript-bot
  • multishiv19
  • eddyverbruggen
  • edusperoni
  • facetious
  • tdermendjiev
  • sis0k0