Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

TypeError: Cannot read property 'client' of undefined #37

Closed
briandilley opened this issue Dec 26, 2017 · 13 comments
Closed

TypeError: Cannot read property 'client' of undefined #37

briandilley opened this issue Dec 26, 2017 · 13 comments

Comments

@briandilley
Copy link
Contributor

This is not the same as issue #14 - the solution provided on that issue does not resolve this issue. This happens at startup, this code used to work just fine but a recent upgrade of libraries/dependencies has brought this issue up. This isn't a problem on the iOS emulator, only the android device that I've tested.

tns version:
3.4.0

package.json:

  "dependencies": {
    "@angular/animations": "~5.0.0",
    "@angular/common": "~5.0.0",
    "@angular/compiler": "~5.0.0",
    "@angular/core": "~5.0.0",
    "@angular/forms": "~5.0.0",
    "@angular/http": "~5.0.0",
    "@angular/platform-browser": "~5.0.0",
    "@angular/platform-browser-dynamic": "~5.0.0",
    "@angular/router": "~5.0.0",
    "@suna/quickride-ts-libcore": "^0.210.0",
    "allow-publish": "^1.0.4",
    "nativescript-angular": "~5.0.0",
    "nativescript-appversion": "~1.4.1",
    "nativescript-geolocation": "~4.2.2",
    "nativescript-google-maps-sdk": "~2.4.3",
    "nativescript-insomnia": "~1.2.1",
    "nativescript-ios-uuid": "~1.0.0",
    "nativescript-phone": "~1.3.1",
    "nativescript-plugin-firebase": "^5.0.5",
    "nativescript-texttospeech": "~2.0.2",
    "nativescript-theme-core": "~1.0.4",
    "nativescript-toast": "^1.4.6",
    "nativescript-websockets": "^1.3.4",
    "reflect-metadata": "~0.1.8",
    "rxjs": "~5.5.2",
    "tns-core-modules": "~3.4.0",
    "zone.js": "~0.8.2"
  },
  "devDependencies": {
    "babel-traverse": "6.26.0",
    "babel-types": "6.26.0",
    "babylon": "6.18.0",
    "lazy": "1.0.11",
    "nativescript-dev-typescript": "~0.6.0",
    "tns-platform-declarations": "^3.1.0",
    "typescript": "~2.4.2"
  }

Here's the error output

ActivityManager: Launch timeout has expired, giving up wake lock!
System.err: java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException:
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: TypeError: Cannot read property 'client' of undefined
System.err: File: "file:///data/data/com.gosuna.quickride.DriverApp/files/app/tns_modules/nativescript-websockets/websockets.js, line: 78, column: 35
System.err:
System.err: StackTrace:
System.err: 	Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/tns_modules/nativescript-websockets/websockets.js', line: 78, column: 36
System.err: 	Frame: function:'require', file:'', line: 1, column: 266
System.err: 	Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/quickride/driver/pages/ride-list/ride.list.page.js', line: 17, column: 10
System.err: 	Frame: function:'require', file:'', line: 1, column: 266
System.err: 	Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/quickride/driver/pages/index.js', line: 8, column: 10
System.err: 	Frame: function:'require', file:'', line: 1, column: 266
System.err: 	Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/quickride/driver/index.js', line: 6, column: 10
System.err: 	Frame: function:'require', file:'', line: 1, column: 266
System.err: 	Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/quickride/index.js', line: 7, column: 10
System.err: 	Frame: function:'require', file:'', line: 1, column: 266
System.err: 	Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/app.module.js', line: 8, column: 19
System.err: 	Frame: function:'require', file:'', line: 1, column: 266
System.err: 	Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/main.js', line: 8, column: 20
System.err: 	Frame: function:'require', file:'', line: 1, column: 266
@NathanaelA
Copy link
Owner

I have released v1.4.0 which fixes a couple issues with all the pull requests that I just finished accepting and testing and then tested it against my WebSocket server.

@arondesign
Copy link

Hi @NathanaelA ,

I've been getting the same issue as well using v1.4.0.

TypeError: Cannot read property 'client' of undefined
File: "file:///data/data/com.aron.debug/files/app/tns_modules/nativescript-websockets/websockets.js, line: 78, column: 35

Everything works fine when running the nativescript application through tns run android, however it throws the error when I extend an existing android application. Any ideas?

@NathanaelA
Copy link
Owner

@arondesign - Based on the error, this actually looks like the app isn't merging in the JAR file properly. Are you using the latest TNS, one of the recent versions had an issue with merging and the fixed it with a later version.

@arondesign
Copy link

@NathanaelA - I am using the latest version of tns, but I think you are right.

After further digging around in android-runtime, it seems to be more of an issue where the extend an existing android application documentation doesn't cover how to move the plugin dependencies over, and pretty much anything else that platforms/android/build.gradle takes care of when building.

@NathanaelA
Copy link
Owner

@Pip3r4o - Can you shed some light on if this is a known issue with the Android runtime?

@petekanev
Copy link

@NathanaelA this seems like a limitation of what @arondesign has already found for himself - the documentation on extending an android application project does not go over how to apply all include.gradle scripts from the nativescript project dependencies, nor how to add the aars and jars as compile dependencies to the project.

I can't offer any immediate workaround/solution to the problem.

@arondesign
Copy link

@Pip3r4o - Exactly, I figured as much. I understand that you do not have any immediate workaround for the overall problem, but do you know of a workaround to simply add a single dependency? In this case, compile('org.java-websocket:Java-WebSocket:1.3.7')

@arondesign
Copy link

@Pip3r4o basically, just this include.gradle

android {
    productFlavors {
        "nativescript-websockets" {
            dimension "nativescript-websockets"
        }
    }
}

dependencies {
    compile('org.java-websocket:Java-WebSocket:1.3.7')
}

@petekanev
Copy link

@arondesign does that not work for you? You could also add the same dependency to app.gradle if you want to keep it to just your project.

@arondesign
Copy link

@Pip3r4o - Well, I've tried that, but it doesn't seem to be a simple as just dropping the dependency in app.gradle (I still get the same error). How do flavors fit into the build process from a cli generated project? When does the type marshaller execute in android-runtime?

@petekanev
Copy link

@arondesign please have a look at https://docs.nativescript.org/runtimes/android/advanced-topics/execution-flow

Metadata for the JavaScript - Java communication is generated at build time. If a Java package is undefined at run time, then it hasn't been present when the build happened.

'Type marshalling' occurs on Java method/constructor calls, as well as on accessing properties - static or otherwise.

Flavors are just the mechanism through which plugin android resources are brought into the application - they do not directly affect what happens at run time.

Perhaps you could create a sample project where the problem is reproducible for me to test locally.

@arondesign
Copy link

@Pip3r4o - Ah.... the metadata. I wasn't copying over the generated metadata between builds - once I did it ran properly. Thanks for the help!

@petekanev
Copy link

@arondesign normally you would not have to do anything manually to have the metadata 'copied over' for your application and the libraries it has, am I missing something in your case?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants