Closed bosencoding closed 8 years ago
Hmm, let me look into this quick for ya.
Can you list your environment versions? Nativescript-cli Nativescript Platform(s)
My environment
"nativescript": {
"id": "org.nativescript.Telephony",
"tns-android": {
"version": "2.2.0"
}
},
"dependencies": {
"nativescript-telephony": "^1.0.2",
"tns-core-modules": "2.2.1"
},
"dependencies": {
"nativescript-telephony": "^1.0.2",
"tns-core-modules": "2.2.1"
},
"devDependencies": {
"babel-traverse": "6.13.0",
"babel-types": "6.13.0",
"babylon": "6.9.0",
"lazy": "1.0.11",
"nativescript-dev-typescript": "^0.3.2",
"typescript": "^1.8.10"
}
nativescript cli version 2.2.1
Dependencies should only be declared once for starts.
Let me try building it from a blank project. It might be the plugin seed generator I used.
I get that error in typescript also in my dev environment.
Build your project and run. It should work just fine.
I just tested this in a new project and everything works fine. I have noticed that it will error if you call Telephony()
before nativeScriptBootstrap(AppComponent)
If the compiler is refusing to build, change noEmitOnError
to false
in your tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"noEmitOnError": false // <<< RIGHT HERE
},
"exclude": [
"node_modules",
"platforms"
]
}
I have the same issue with Nativescript 2.4.0 with a very simple test project according to the instructions:
import { Component, OnInit } from "@angular/core";
//import {Telephony} from 'nativescript-telephony';
var Telephony = require('nativescript-telephony');
@Component({
selector: "my-app",
templateUrl: "app.component.html",
})
export class AppComponent implements OnInit {
constructor() {}
ngOnInit() {
Telephony().then((resolved) => {
console.log('resolved >', resolved)
console.dir(resolved);
}).catch((error) => {
console.error('error >', error)
console.dir(error);
});
}
}
Am getting this:
JS: EXCEPTION: Error in ./AppComponent class AppComponent_Host - inline template:0:0 caused by: Telephony is not a function
JS: ORIGINAL EXCEPTION: Telephony is not a function
JS: ORIGINAL STACKTRACE:
JS: TypeError: Telephony is not a function
JS: at AppComponent.ngOnInit (/data/data/org.nativescript.testjoni/files/app/app.component.js:9:9)
JS: at Wrapper_AppComponent.detectChangesInInputProps (/AppModule/AppComponent/wrapper.ngfactory.js:18:53)
JS: at DebugAppView._View_AppComponent_Host0.detectChangesInternal (/AppModule/AppComponent/host.ngfactory.js:30:26)
JS: at DebugAppView.AppView.detectChanges (/data/data/org.nativescript.testjoni/files/app/tns_modules/@angular/core/bundles/core.umd.js:9305:18)
JS: at DebugAppView.detectChanges (/data/data/org.nativescript.testjoni/files/app/tns_modules/@angular/core/bundles/core.umd.js:9410:48)
JS: at ViewRef_.detectChanges (/data/data/org.nativescript.testjoni/files/app/tns_modules/@angular/core/bundles/core.umd.js:7398:24)
JS: at /data/data/org.nativescript.testjoni/files/app/tns_modules/@angular/core/bundles/core.umd.js:6819:88
JS: at Array.forEach (native)
JS: at ApplicationRef_.tick (/data/data/org.nativescript.testjoni/files/app/tns_modules/@angular/core/bundles/core.umd.js:6819:42)
JS: at ApplicationRef_._loadComponent (/data/data/org.nativescript.testjoni/files/app/tns_modules/@angular/core/bundles/core.umd.js:6797:18)
JS: ERROR CONTEXT:
JS: [object Object]
JS: ns-renderer: ERROR BOOTSTRAPPING ANGULAR
JS: ns-renderer: Error in ./AppComponent class AppComponent_Host - inline template:0:0 caused by: Telephony is not a function
My env:
$ tns info
All NativeScript components versions information
┌──────────────────┬─────────────────┬────────────────┬─────────────┐
│ Component │ Current version │ Latest version │ Information │
│ nativescript │ 2.4.0 │ 2.4.0 │ Up to date │
│ tns-core-modules │ 2.4.0 │ 2.4.0 │ Up to date │
│ tns-android │ 2.4.1 │ 2.4.1 │ Up to date │
│ tns-ios │ 2.4.0 │ 2.4.0 │ Up to date │
└──────────────────┴─────────────────┴────────────────┴─────────────┘
Remove node_modules
, platforms
, folders and reinstall.
Hi @roblav96 thanks for your reply. Actually it is working just fine. When using require instead of import you need to refer to the function Telephony() as part of the object assigned to the var. Something like this:
import { Component, OnInit } from "@angular/core";
//import {Telephony as Sim} from 'nativescript-telephony';
var Sim = require('nativescript-telephony');
@Component({
selector: "my-app",
templateUrl: "app.component.html",
})
export class AppComponent implements OnInit {
constructor() {}
ngOnInit() {
Sim.Telephony().then((resolved) => {
console.log('resolved >', resolved)
console.dir(resolved);
}).catch((error) => {
console.error('error >', error)
console.dir(error);
});
}
}
Hi, i have annoying problem after install this plugin, i tried to run in my android phone and got error.
with 'import'
import {Telephony} from "nativescript-telephony"
result :
with 'var'
var Telephony = require('nativescript-telephony');
result :
I've missed something?
Thank you