EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 441 forks source link

Cannot read property 'ads' of undefined #1716

Closed plackowski closed 4 years ago

plackowski commented 4 years ago

Hi, maybe it's related to last changes with 11.1.1 (I didn't change anything in my app, just deleted node_modules and install dependencies again) but now I have errors:

Restarting application on device emulator-5554...
Successfully synced application com.pixelcore.voclick on device emulator-5554.
System.err: An uncaught Exception occurred on "main" thread.
System.err: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function 
System.err: TypeError: Cannot read property 'ads' of undefined
System.err: File: (file: node_modules\@nativescript\firebase\firebase.android.js:24:0)
System.err: 
System.err: StackTrace:
System.err: ../node_modules/@nativescript/firebase/firebase.js(file: node_modules\@nativescript\firebase\firebase.android.js:24:0)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at ./app/core/services/auth/auth.service.ts(file:///data/data/com.pixelcore.voclick/files/app/bundle.js:1693:80)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at ./app/core/security/can-activate.guard.ts(file:///data/data/com.pixelcore.voclick/files/app/bundle.js:1236:85)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at ./app/app.common.ts(file: src\app\app.common.ts:4:0)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at ./app/app.module.tns.ts(file: src\app\app.module.tns.ts:1:0)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at (file: src\main.tns.ts:1:106)
System.err:     at ./main.tns.ts(file:///data/data/com.pixelcore.voclick/files/app/bundle.js:6544:30)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at checkDeferredModules(file: src\webpack\bootstrap:43:0)
System.err:     at webpackJsonpCallback(file: src\webpack\bootstrap:30:0)
System.err:     at (file:///data/data/com.pixelcore.voclick/files/app/bundle.js:2:57)
System.err:     at require(:1:266)
System.err:
System.err:
System.err: TypeError: Cannot read property 'ads' of undefined
System.err: 
System.err: StackTrace:
System.err: java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function      
System.err: TypeError: Cannot read property 'ads' of undefined
System.err: File: (file: node_modules\@nativescript\firebase\firebase.android.js:24:0)
System.err: 
System.err: StackTrace:
System.err: ../node_modules/@nativescript/firebase/firebase.js(file: node_modules\@nativescript\firebase\firebase.android.js:24:0)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at ./app/core/services/auth/auth.service.ts(file:///data/data/com.pixelcore.voclick/files/app/bundle.js:1693:80)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at ./app/core/security/can-activate.guard.ts(file:///data/data/com.pixelcore.voclick/files/app/bundle.js:1236:85)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at ./app/app.common.ts(file: src\app\app.common.ts:4:0)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at ./app/app.module.tns.ts(file: src\app\app.module.tns.ts:1:0)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at (file: src\main.tns.ts:1:106)
System.err:     at ./main.tns.ts(file:///data/data/com.pixelcore.voclick/files/app/bundle.js:6544:30)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at checkDeferredModules(file: src\webpack\bootstrap:43:0)
System.err:     at webpackJsonpCallback(file: src\webpack\bootstrap:30:0)
System.err:     at (file:///data/data/com.pixelcore.voclick/files/app/bundle.js:2:57)
System.err:     at require(:1:266)
System.err:
System.err:
System.err: TypeError: Cannot read property 'ads' of undefined
System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5743)
System.err:     at android.app.ActivityThread.-wrap1(Unknown Source:0)
System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
System.err:     at android.os.Looper.loop(Looper.java:164)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6494)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
System.err: Caused by: com.tns.NativeScriptException: Error calling module function 
System.err: TypeError: Cannot read property 'ads' of undefined
System.err: File: (file: node_modules\@nativescript\firebase\firebase.android.js:24:0)
System.err:
System.err: StackTrace: 
System.err: ../node_modules/@nativescript/firebase/firebase.js(file: node_modules\@nativescript\firebase\firebase.android.js:24:0)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at ./app/core/services/auth/auth.service.ts(file:///data/data/com.pixelcore.voclick/files/app/bundle.js:1693:80)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at ./app/core/security/can-activate.guard.ts(file:///data/data/com.pixelcore.voclick/files/app/bundle.js:1236:85)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at ./app/app.common.ts(file: src\app\app.common.ts:4:0)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at ./app/app.module.tns.ts(file: src\app\app.module.tns.ts:1:0)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at (file: src\main.tns.ts:1:106)
System.err:     at ./main.tns.ts(file:///data/data/com.pixelcore.voclick/files/app/bundle.js:6544:30)
System.err:     at __webpack_require__(file: src\webpack\bootstrap:74:0)
System.err:     at checkDeferredModules(file: src\webpack\bootstrap:43:0)
System.err:     at webpackJsonpCallback(file: src\webpack\bootstrap:30:0)
System.err:     at (file:///data/data/com.pixelcore.voclick/files/app/bundle.js:2:57)
System.err:     at require(:1:266)
System.err: 
System.err:
System.err: TypeError: Cannot read property 'ads' of undefined
System.err:     at com.tns.Runtime.runModule(Native Method)
System.err:     at com.tns.Runtime.runModule(Runtime.java:689)
System.err:     at com.tns.Runtime.run(Runtime.java:681)
System.err:     at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
System.err:     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5740)
System.err:     ... 8 more

Any idea?

EddyVerbruggen commented 4 years ago

I actually saw the same when running the demo app today after merging the v11 plugin version into master. Not sure why this dependency is missing at runtime.

@NathanWalker do you perhaps have an idea? Maybe you've teste tested the demo app locally and didn't have the problem?

NathanWalker commented 4 years ago

In the demo it seems none of the google api's are loaded on Android com.google.firebase is unavailable. Will see what can find out about the implementation handling perhaps in postinstaller; not sure - does seem strange.

lehongwang commented 4 years ago

I got this error too :(((

Klunk75 commented 4 years ago

Same issue too, with version 11.1.1. Downgraded to version 11.1.0 and it works, no issues.

plackowski commented 4 years ago

Downgraded to 11.1.0 and.. not works :/ - the same errors

nikoTM commented 4 years ago

@Arystosedes try removing platform and adding again, downgrading worked for me as well

plackowski commented 4 years ago

@nikoTM But I did it. My package.json:

"dependencies": { "@angular/animations": "~10.2.1", "@angular/cdk": "^10.2.7", "@angular/common": "~10.2.1", "@angular/compiler": "~10.2.1", "@angular/core": "~10.2.1", "@angular/fire": "^6.0.4", "@angular/forms": "~10.2.1", "@angular/material": "^10.2.7", "@angular/platform-browser": "~10.2.1", "@angular/platform-browser-dynamic": "~10.2.1", "@angular/router": "~10.2.1", "@nativescript/angular": "~10.1.7", "@nativescript/core": "~7.0.13", "@nativescript/firebase": "^11.1.0", "@nativescript/theme": "~3.0.0", "@ngx-translate/core": "^13.0.0", "@ngx-translate/http-loader": "^6.0.0", "core-js": "^3.6.5", "firebase": "^8.0.0", "nativescript-gif": "^5.0.0", "nativescript-sound": "^1.0.4", "nativescript-texttospeech": "^3.0.1", "nativescript-toasty": "^2.0.1", "nativescript-toasty-ns-7": "^14.0.0", "nativescript-ui-chart": "^8.0.2", "nativescript-ui-listview": "^9.0.4", "nativescript-ui-sidedrawer": "9.0.3", "ngx-custom-validators": "^10.0.0", "npm-check-updates": "^9.2.3", "reflect-metadata": "~0.1.13", "rxjs": "~6.6.3", "tslib": "2.0.3", "zone.js": "~0.11.2" }, "devDependencies": { "@angular-devkit/build-angular": "~0.1002.0", "@angular/cli": "~10.2.0", "@angular/compiler-cli": "~10.2.1", "@nativescript/android": "7.0.1", "@nativescript/schematics": "^10.1.0", "@nativescript/tslint-rules": "~0.0.5", "@nativescript/webpack": "~3.0.8", "@types/jasmine": "~3.6.0", "@types/jasminewd2": "~2.0.8", "@types/node": "^14.14.6", "@types/stripe-v3": "^3.1.21", "codelyzer": "^6.0.1", "jasmine-core": "~3.6.0", "jasmine-spec-reporter": "~6.0.0", "karma": "~5.2.3", "karma-chrome-launcher": "~3.1.0", "karma-coverage-istanbul-reporter": "~3.0.3", "karma-jasmine": "~4.0.1", "karma-jasmine-html-reporter": "^1.5.4", "node-sass": "^4.14.1", "protractor": "~7.0.0", "ts-node": "~9.0.0", "tslint": "~6.1.3", "typescript": "~4.0.5" }

nikoTM commented 4 years ago

@Arystosedes "@nativescript/firebase": "^11.1.0", will install latest if you run tns install, what does npm ls --depth=0 | grep firebase return?

  1. ns platform remove android
  2. npm i @nativescript/firebase@11.1.0
  3. ns debug android

Worked for me

plackowski commented 4 years ago

@nikoTM Yes! Now it's working, thx!

NathanWalker commented 4 years ago

Confirmed 11.1.0 is good - 11.1.1 does not include the android libs. @EddyVerbruggen seems like somehow the postinstall is not adding the gradle libs in 11.1.1 - but 11.1.0 is fine.

EddyVerbruggen commented 4 years ago

@NathanWalker Yeah indeed, not sure what changed to kill that. Maybe it's the typescript 4 bump, but I don't see how.

Btw, did your 11.1.1-rc.0 work fine? If so, then it's a build issue on my machine. If it didn't work well then it's a code change.

NathanWalker commented 4 years ago

@EddyVerbruggen confirmed "@nativescript/firebase": "11.1.1-rc.0", works perfect as well. Possible when you published 11.1.1 maybe a .js file didn't make it? I can pull down packs of both and see what I can tell - a file must be missing from 11.1.1.

EddyVerbruggen commented 4 years ago

Hmm, @NathanWalker perhaps you’re publishing it differently? I’ve always used the publish.sh script in the publish folder.

Perhaps it’s wise if you could just publish 11.1.2 and afterwards I figure it out.

Cheers!

NathanWalker commented 4 years ago

Curiously if I reset to this commit: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/commit/02474da6842ebbf22d3a8f1367354ff85c1d5e4f

git checkout 02474da

Everything works (albeit some typings errors/warnings when running demo but demo runs and works just fine for majority of all the apis in demo) so it's something in the commits subsequent to that which cause it. Haven't tracked it down yet but can look more on Wednesday. I have hunch that something in this changeset causes the issue: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/commit/4a8089b5b53e60a36c0e0baa89190df9f041ddbb

EddyVerbruggen commented 4 years ago

@NathanWalker Thanks, that was very helpful and I found the culprit. Let me do a final check.

EddyVerbruggen commented 4 years ago

So it was this not being in the package.json: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/53dac31b58d9437ff9f7072e7fb371af2bfeb11f/src/package.json#L8-L11

Didn't affect iOS, did affect Android apparently.

11.1.2 published, thanks for the help!

NathanWalker commented 4 years ago

Good to note thanks @EddyVerbruggen - yes any plugin that has ios/android parts to it (meaning they have platforms/ios or platforms/android folders in them) should keep that key there as cli uses it to include the platform libs that way 👍 - that makes perfect sense now.

Burgov commented 4 years ago

Thanks for the patch! Had the same issue with firebase analytics, this update fixed it.

darkyelox commented 3 years ago

This still happening on 11.1.3 in Android only, have to downgrade to 11.1.2 and worked

wjoane commented 3 years ago

This still happening on 11.1.3 in Android only, have to downgrade to 11.1.2 and worked

Same here, 11.1.3 isn't working, downgrading didn't help

sleignnet commented 2 years ago

I had this same issue - cannot read property 'ads' of undefined. For me, I had removed the firebase plugin by deleting the node_modules directory, and after re-downloading the plugin, that's when I started getting the error message.

However, if you go into the firebase directory and run npm run setup and then npm run config it will take you thru the setup process, at which point I was able to compile the app without having any further issues