nativescript-plugin-firebase icon indicating copy to clipboard operation
nativescript-plugin-firebase copied to clipboard

Using analytics throws some warnings

Open rickwalking opened this issue 5 years ago • 11 comments

If I try to use analytics importing firebase like this, it doesn't have analytics in autocomplete:

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

So, I'm importing it like this:

import * as firebase from '@nativescript/firebase'; With this kind of import, it does provide analytics in autocomplete, but there's warnings being shown while building the app:

WARNING in ./app/services/xxx.service.ts 20:12-30
"export 'analytics' (imported as 'firebase') was not found in '@nativescript/firebase'
 @ ./app/modules/main/services/yyy.service.ts
 @ ./app/app.module.ts
 @ ./main.ts

I'm using @nativescript/firebase version 11.0.0.

rickwalking avatar Oct 14 '20 12:10 rickwalking

same here

PhilippS93 avatar Oct 15 '20 14:10 PhilippS93

I also have TypeError: Cannot read property 'setScreenName' of undefined

befirst avatar Oct 21 '20 09:10 befirst

at FirebaseAnalyticsService.logPageView (file: app/shared/services/firebase-analytics.service.ts:29:23)
at AnalyticsService.logPageView (file: app/shared/services/analytics.service.ts:18:27)
at MainComponent.ngOnInit (file: app/pages/main/main.component.ts:182:19)
at callHook (file: node_modules/@angular/core/fesm2015/core.js:3105:0)
at callHooks (file: node_modules/@angular/core/fesm2015/core.js:3075:0)
at executeInitAndCheckHooks (file: node_modules/@angular/core/fesm2015/core.js:3027:0)
at refreshView (file: node_modules/@angular/core/fesm2015/core.js:7333:0)
at refreshEmbeddedViews (file: node_modules/@angular/core/fesm2015/core.js:8419:0)
at refreshView (file: node_modules/@angular/core/fesm2015/core.js:7342:0)
at refreshEmbeddedViews (file: node_modules/@angular/core/fesm2015/core.js:8419:0)
at refreshView (file: node_modules/@angular/core/fesm2015/core.js:7342:0)
at refreshComponent (file: node_modules/@angular/core/fesm2015/core.js:8465:0)
at refreshChildComponents (file: node_modules/@angular/core/fesm2015/core.js:7126:0)
at refreshView (file: node_modules/@angular/core/fesm2015/core.js:7368:0)
at renderComponentOrTemplate (file: node_modules/@angular/core/fesm2015/core.js:7432:0)

befirst avatar Oct 21 '20 09:10 befirst

  logPageView(name: string): void {
    firebase.analytics.setScreenName({          <-----here is the 29th line
      screenName: name
    });
  }

befirst avatar Oct 21 '20 09:10 befirst

I tried both import * as firebase from '@nativescript/firebase'; and import { analytics } from '@nativescript/firebase';

befirst avatar Oct 21 '20 09:10 befirst

@EddyVerbruggen it's happened after upgrading to "@nativescript/firebase": "^11.0.0"

befirst avatar Oct 21 '20 10:10 befirst

Import analytics like this instead:

import { analytics } from '@nativescript/firebase/analytics';

timdoege avatar Oct 22 '20 09:10 timdoege

@timdoege thanks for the tip, this fixed it for me for various packages. I was importing directly from @nativescript/firebase and while Visual Studio Code seems happy with that (doesn't complain there is no export) it fails while building. Importing from the subfolder of the package fixes it.

Seems this is only for the packages that have their own folder in https://github.com/EddyVerbruggen/nativescript-plugin-firebase/tree/master/src as for example firestore can be imported directly from @nativescript/firebase, not @nativescript/firebase/firestore.

So as of now, I think you have to import individually:

  • admob
  • analytics
  • crashlytics
  • functions
  • inappmessaging
  • messaging
  • mlkit
  • performance
  • storage

tomups avatar Oct 22 '20 14:10 tomups

According to @tomtastico answer, it seems like there's issues happening on version 11.0.0 about importing analytics without using deep imports.

rickwalking avatar Oct 26 '20 22:10 rickwalking

I tried both import * as firebase from '@nativescript/firebase'; and import { analytics } from '@nativescript/firebase';

This works Fine Thanks a lot

xpalacincreditoh avatar Nov 25 '21 08:11 xpalacincreditoh

I only have to migrate from .migration_backup/webpack.config.js:

const countryFiles = require('./lib/copy-country-files');

module.exports = env => {
   const {
        ...
        // You can provide the following flags when running 'tns run android|ios'
        ....
        country, // --env.country
    } = env;
   
   if (country) {
        countryFiles.checkCountryFiles(country);
    }
};

and in .migration_backup/lib/copy-country-files.js:

var path = require('path');
var fs = require('fs'); 
var mkdirp = require('mkdirp');

var copyFileSync = function( source, target ) {
    var targetFile = target;
    //if target is a directory a new file with the same name will be created
    if ( fs.existsSync( target ) ) {
        if ( fs.lstatSync( target ).isDirectory() ) {
            targetFile = path.join( target, path.basename( source ) );
        }
    } else {
        fs.mkdirSync( target );
        targetFile = path.join( target, path.basename( source ) );
    }
    fs.writeFileSync(targetFile, fs.readFileSync(source));
};

var copyFolderRecursiveSync = function( source, target, rootName ) {
    var files = [];

    if (rootName == null) {
        rootName = source
    }
    //check if folder needs to be created or integrated
    var targetFolder = path.join( target, path.basename( rootName ) );
    if ( !fs.existsSync( targetFolder ) ) {
        fs.mkdirSync( targetFolder );
    }
    //copy
    if ( fs.lstatSync( source ).isDirectory() ) {
        files = fs.readdirSync( source );
        files.forEach( function ( file ) {
            var curSource = path.join( source, file );
            if ( fs.lstatSync( curSource ).isDirectory() ) {
                copyFolderRecursiveSync( curSource, targetFolder );
            } else {
                copyFileSync( curSource, targetFolder );
            }
        } );
    }
};

var checkCountryFiles = function(country) {
    return new Promise(function (resolve, reject) {
        const source = `./country-apps/${country}/app/.`;
        if (fs.existsSync(source)) {
            copyFolderRecursiveSync(source,'./app/');
            resolve();
        }
        reject('No country folder found');
    });
};

module.exports = {
    copyFileSync,
    copyFolderRecursiveSync,
    checkCountryFiles,
}

xpalacincreditoh avatar Nov 25 '21 10:11 xpalacincreditoh