PeterStaev / nativescript-azure-mobile-apps

:cloud: NativeScript plugin for working with Microsoft Azure Mobile Apps services
Apache License 2.0
30 stars 10 forks source link

Error : Cannot read property MobileServiceAuthenticationProvider of undefined #30

Closed SamuelThomas78 closed 5 years ago

SamuelThomas78 commented 5 years ago

I just install the plugin on my nativescript Angular App by running -> tns plugin add nativescript-azure-mobile-apps But if i put in my component -> import { MobileServiceClient } from "nativescript-azure-mobile-apps/client"; var client = new MobileServiceClient("https://mymobileapp.azurewebsites.net");

I get the error -> Error calling module function TypeError: Cannot read property 'MobileServiceAuthenticationProvider' of undefined File nativescript-azure-mobile-apps/client/client.js, line: 29, column: 141

Any ideas how i could make it walk ? Should i import a module in my app.module.ts ?

PeterStaev commented 5 years ago

Hey @SamuelThomas78 , seems something is not set up correctly. Try clearing you platforms, removing your app from the device and then running it again.

SamuelThomas78 commented 5 years ago

Hello, Thanks for this fast answer, I try removing the app and relaunch it but i got same error. This my package.jon { "nativescript": { "id": "org.nativescript.***", "tns-android": { "version": "4.2.0" }, "tns-ios": { "version": "4.2.0" } }, "description": "NativeScript Application", "license": "SEE LICENSE IN ", "repository": "", "scripts": { "lint": "tslint \"app//*.ts\"" }, "dependencies": { "@angular/animations": "~6.1.0", "@angular/common": "~6.1.0", "@angular/compiler": "~6.1.0", "@angular/core": "~6.1.0", "@angular/forms": "~6.1.0", "@angular/http": "~6.1.0", "@angular/platform-browser": "~6.1.0", "@angular/platform-browser-dynamic": "~6.1.0", "@angular/router": "~6.1.0", "nativescript-angular": "~6.1.0", "nativescript-azure-mobile-apps": "^2.0.3", "nativescript-theme-core": "~1.0.4", "nativescript-ui-sidedrawer": "~4.2.0", "reflect-metadata": "~0.1.10", "rxjs": "~6.2.0", "tns-core-modules": "~4.2.0", "zone.js": "~0.8.18" }, "devDependencies": { "@nativescript/schematics": "~0.2.5", "codelyzer": "~4.3.0", "nativescript-dev-sass": "~1.6.0", "nativescript-dev-typescript": "~0.7.0", "nativescript-dev-webpack": "~0.16.0", "tslint": "~5.11.0", "typescript": "~2.7.2", "@angular/compiler-cli": "~6.1.0", "@ngtools/webpack": "~6.2.0" }, "readme": "NativeScript Application" }

My component looks like this : import { Component, OnInit } from '@angular/core'; import { TextField } from "ui/text-field"; import { MobileServiceClient } from "nativescript-azure-mobile-apps/client";

@Component({ selector: 'login', moduleId: module.id, templateUrl: './login.component.html', styleUrls: ['./login.component.scss'] }) export class LoginComponent implements OnInit {

constructor() { }

ngOnInit() { var s = MobileServiceClient.configureClientAuthAppDelegate() //var client = new MobileServiceClient("https://****.azurewebsites.net"); //var todoItemTable = client.getTable("TodoItem"); /*

If i comment the var s = MobileServiceClient.configureClientAuthAppDelegate() lign it walks If i uncommented it i got the error. I got the error on my s7 samsung connected usb device. I launch the app by clicking run into device on Nativescript SideKick I try on other device and got same error :/ Any ideas ?

PeterStaev commented 5 years ago

The configureClientAuthAppDelegate is ONLY for ios. For android this is a dummy empty function, and i doubt that will cause a problem, But if you are running android only then you dont need that. Also not sure where you would put that for angular based project, but i dont think in the components is a good idea. May be it should be in the main.ts before you bootstrap the app, but not 100% sure.

SamuelThomas78 commented 5 years ago

Hello, Even if i try to put it in the main.ts which so like like this -> `// this import should be first in order to load some required settings (like globals and reflect-metadata) import { platformNativeScriptDynamic } from "nativescript-angular/platform";

import { AppModule } from "./app/app.module";

import { MobileServiceClient } from "nativescript-azure-mobile-apps/client"; console.log(MobileServiceClient);

platformNativeScriptDynamic().bootstrapModule(AppModule); ` I get the same error -> Error calling module function TypeError: Cannot read property 'MobileServiceAuthenticationProvider' of undefined File nativescript-azure-mobile-apps/client/client.js, line: 29, column: 141

I look into the client.js file and it is this which is undefined -> com.microsoft.windowsazure.mobileservices.authentication

If i comment: console.log(MobileServiceClient); lign -> app is running normaly ! I dont understand how i can use this library with angular. If you just create a fresh new nativescript angular app and install nativescript-azure-mobile-apps, you'll see that it does not walk. Please help !

SamuelThomas78 commented 5 years ago

Hello , I finaly make it work by deleting the platforms folder and delete the app on my device. Relaunching the app made it work. First time I try it did not walk I dont know why ! Anyway thank you @PeterStaev !