nativescript-plugin-firebase
nativescript-plugin-firebase copied to clipboard
Using analytics throws some warnings
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.
same here
I also have TypeError: Cannot read property 'setScreenName' of undefined
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)
logPageView(name: string): void {
firebase.analytics.setScreenName({ <-----here is the 29th line
screenName: name
});
}
I tried both
import * as firebase from '@nativescript/firebase';
and
import { analytics } from '@nativescript/firebase';
@EddyVerbruggen it's happened after upgrading to "@nativescript/firebase": "^11.0.0"
Import analytics like this instead:
import { analytics } from '@nativescript/firebase/analytics';
@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:
admobanalyticscrashlyticsfunctionsinappmessagingmessagingmlkitperformancestorage
According to @tomtastico answer, it seems like there's issues happening on version 11.0.0 about importing analytics without using deep imports.
I tried both
import * as firebase from '@nativescript/firebase';andimport { analytics } from '@nativescript/firebase';
This works Fine Thanks a lot
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,
}