Nativescript: Error in properties.js from tns-core-modules

Created on 8 May 2017  ยท  63Comments  ยท  Source: NativeScript/NativeScript

I upgraded my app from {N} v2.something to v3.0 and now I have an error inside the tns-core-modules (which I also updated to 3.0.0).

Here is what I think is the relevant part:

TypeError: Cannot read property 'prototype' of undefined
File: "file:///data/data/org.nativescript.HonkMeNative/files/app/tns_modules/tns-core-
modules/ui/core/properties/properties.js, line: 461, column: 33

You can find the full stack-trace on PasteBin

I can realize that I've messed up, as the defaul HelloWorld app works, until I replace it with my code, but I have no clue where to start investigating.

It looks CSS related from snooping inside the code, but I have no CSS other than an empty module css and the default app.css.

bug done

Most helpful comment

@bradmartin @sitefinitysteve I'll try to get my hands on a Galaxy S7 and see what gives.

All 63 comments

Same problem. Which is weird because it was working on 3.0 just a few days ago.

Found a fix that worked for me: Uninstall the app from the emulator and delete the platforms/android folder.

@ryanlangton Did that several times with almost no success. Worked one time, but the next time I changed something it broke again (even after undo-ing that "something")

Hi @surdu,
Thank you for reporting this issue

If I understand you correctly this issue is not reproduced with clear NativeScript project.
Regarding that, it would help if you could provide some more info about the problem.
Also, you could send us sample project, where the problem could be debugged locally.

Thank you in advance for your cooperation.

Yes, the default project created by tns create works perfectly.

Hi @surdu,
Thank you for the sample project.
I tested it on my side, however, was unable to reproduce this behavior.
After I build the app I receive some of the available responses in the terminal.

### CONNECTION FAILED ###

or

### CONNECTED ###

Regarding that you could verify, whether you are using the latest CLI 3.0 ->tns --version. Also, you could delete node_modules and platforms folders and to build it again with tns run android.

Could you also give us info about the device or emulator, which you are using for testing?

I don't think deleting those folders will help, as I've started from scratch repeatedly with the same issue.

I'm running the code on a OnePlus 3T.

I'll check the version when I get home, but I'm 98.6% sure it's 3.0.

Hi @surdu,
Did you verify, whether you are using latest CLI 3.0?

No, sorry. I fell asleep as soon as I got home ๐Ÿ˜ž

I'll do my best today ๐Ÿ˜„

@tsonevn I've tested and tns --version confirms it's 3.0.0.

Do you think it could be device dependent ? I can't test on the Simulator, but I might try to fire up my old Nexus 4

I have same problem

`
An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.nativescript.bonapp/com.tns.NativeScriptActivity}: com.tns.NativeScriptException:

Error calling module function

Error calling module function

Error calling module function

Error calling module function

Error calling module function

Error calling module function

Error calling module function

Error calling module function

Error calling module function

TypeError: Cannot read property 'prototype' of undefined
File: "file:///data/data/org.nativescript.bonapp/files/app/tns_modules/tns-core-modules/ui/core/properties/properties.js, line: 461, column: 33

StackTrace:
Frame: function:'CssProperty.register', file:'file:///data/data/org.nativescript.bonapp/files/app/tns_modules/tns-core-modules/ui/core/properties/properties.js', line: 461, column: 34
Frame: function:'', file:'file:///data/data/org.nativescript.bonapp/files/app/tns_modules/tns-core-modules/ui/styling/style-properties.js', line: 149, column: 26
Frame: function:'require', file:'', line: 1, column: 266
Frame: function:'', file:'file:///data/data/org.nativescript.bonapp/files/app/tns_modules/tns-core-modules/ui/animation/animation.js', line: 6, column: 26
Frame: function:'require', file:'', line: 1, column: 266
Frame: function:'', file:'file:///data/data/org.nativescript.bonapp/files/app/tns_modules/tns-core-modules/ui/styling/converters.js', line: 3, column: 19
Frame: function:'require', file:'', line: 1, column: 266
Frame: function:'', file:'file:///data/data/org.nativescript.bonapp/files/app/tns_modules/tns-core-modules/ui/styling/style.js', line: 7, column: 18
Frame: function:'require', file:'', line: 1, column: 266
Frame: function:'', file:'file:///data/data/org.nativescript.bonapp/files/app/tns_modules/tns-core-modules/ui/core/view-common.js', line: 2, column: 13
Frame: function:'require', file:'', line: 1, column: 266
Frame: function:'', file:'file:///data/data/org.nativescript.bonapp/files/app/tns_modules/tns-core-modules/ui/core/view.js', line: 1, column: 78
Frame: function:'require', file:'', line: 1, column: 266
Frame: function:'', file:'file:///data/data/org.nativescript.bonapp/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 5, column: 14
Frame: function:'require', file:'', line: 1, column: 266
Frame: function:'', file:'file:///data/data/org.nativescript.bonapp/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 5, column: 22
Frame: function:'require', file:'', line: 1, column: 266
Frame: function:'', file:'file:///data/data/org.nativescript.bonapp/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 2, column: 15
Frame: function:'require', file:'', line: 1, column: 266
`

and later

Successfully synced application org.nativescript.bonapp on device 73QDU168280048*

05-11 01:04:50.974 13035 13035 W System.err: at com.tns.Runtime.createJSInstance(Runtime.java:593)
chromium: [INFO:library_loader_hooks.cc(140)] Chromium logging enabled: level = 0, default verbosity = 0
05-11 01:09:37.628 6797 6797 I cr_BrowserStartup: Initializing chromium process, singleProcess=true
chromium: [INFO:CONSOLE(402)] "Uncaught IndexSizeError: Failed to execute 'getRangeAt' on 'Selection': 0 is not a valid index.", source: file:///android_asset/draft_editor.js (402)

eug-MacBook-Pro:bonapp eug$ tns --version
3.0.0-2017-05-05-8820
eug-MacBook-Pro:bonapp eug $ tsc -v
Version 2.3.2
eug-MacBook-Pro:bonapp eug $

Deleting node_modules, platfotms, app from device didn't help. Reinstalling nativescript too

And weird problems with http after upgrade.

But then I write let http = require('http'); ts compiling without errors

import http = require('http');

...

http.request({ url: url, method: 'POST', headers: {'Content-Type': 'application/json'}, content: JSON.stringify(data) })
....

src/services/HttpRequestService.ts(29,8): error TS2345: Argument of type '{ url: string; method: string; headers: { 'Content-Type': string; }; content: string; }' is not assignable to parameter of type 'RequestOptions'.
Object literal may only specify known properties, and 'url' does not exist in type 'RequestOptions'.

src/services/HttpRequestService.ts(42,9): error TS2339: Property 'getJSON' does not exist on type 'typeof "http"'.

src/services/HttpRequestService.ts(51,5): error TS2345: Argument of type '{ url: string; method: string; }' is not assignable to parameter of type 'RequestOptions'.
Object literal may only specify known properties, and 'url' does not exist in type 'RequestOptions'.

Hi @surdu @woozie,
Could you verify, whether you will have the same problem with a clear project, while using our Hellow world template->tns create test?
I am still unable to reproduce this case on my side and projects seem to be built normally.
Something that could be related is an issue with Android SDK Build-tools, which are installed in Android SDK Manager. Verify whether you have Android Build-tools version 25.0.2.
screen shot 2017-05-11 at 1 04 10 pm

@woozie, the issue seems to be an error with typescript transpilation, which could be lead from using an old version of nativescript-dev-typescript. To fix this, you could follow the below-attached steps.

  1. npm uninstall nativescript-dev-typescript --save-dev
  2. npm uninstall typescript --save-dev
  3. npm install [email protected] --save-dev

@tsonevn Thank you, sdk update helps me. But only for Emulator with Android 6
On my phone Honor 8 with Android 7.0 still problem.

nativescript-dev-typescript didn't update, I had latest version

And still problem with http

@tsonevn In my case, updating SDK build tools to 25.0.2 didn't helped nor did 25.0.3 :frowning_face:

Just for completeness, my phone is a OnePlus 3T running Android 7.1.1. I am using vanilla JS with NativeScript.

@woozie @surdu Can you reproduce the issue on Android 7 (or 7.1) emulators?

@dtopuzov, I can reproduce on Android 7.1 emulator as well as on real Android 7.1 device.

Same problem for me, but the error does not reproduce on emulator, only on real Android device (HTC M8)

Update: for me the problem was gone on Android device after I completely unistalled the previously installed apk of the earlier version, rather than installing the new one as an update!

+1 for this issue. Have updated SDK, Typescript dependencies, removed platforms/android and started fresh. Default 'hello world' app works fine for me as well upon create. Also works on Android 6 emulator, from what I can tell.

Have been struggling with this one for a few days now, will post some more findings in a bit.

Hi @surdu , @miltador , @woozie ,
Could you verify, whether the give solution from @tigrenok00 will work for you?

@tsonevn, uninstalled on my phone and started again. The same issue.
By the way: I have the same error on my phone with Hello world application.

@tsonevn No, it doesn't work for me, but I have updates.

I've installed the application on my Nexus 4 which runs Android 5.1.1, the same build, and it runs correctly (or at least to the point where I get an error I was expecting about the fact my IntentService doesn't have a no argument constructor (which is the reason I updated to 3.0.0)).

Hi @miltador,
Could you send us the sample project, which you created with the Hello world template while including the platforms and node_modules folder?
Also, could you provide some info about the OS and if you are using Windows or Mac OS?

I guess what problem in device settings.

Today I built my app without any problems, restarted commands several times and problem again

Hi @miltador @surdu,
Did you still have the same problem or you were able to solve it? Could you send me sample project, which includes the platform and node_modules folders?

This will help us to investigate further this behavior.

I just ran into this tonight. Updated an app two days ago to 3.0 - everything worked great. Sit down tonight to work and once I exec tns run android this same error related to properties.js line 461. I'm currently going through some things to see what can help to resolve since it worked prior on my device (Motorola Droid Turbo 2)

I actually realized it never worked on my phone running android 7.1 (didn't have a good USB cable the other night so only emulators). I updated the app to NS 3.0 and it ran fine on genymotion emulators with android 5.1, 6.0, and 7.1. I've also confirmed again that I can only get this to crash running on my phone (Droid Turbo 2 running android 7.1). The app runs fine on all genymotion emulators I have running and will consistently crash on startup with the message below. The Error calling module function message will print 9 times before the message below and StackTrace.

TypeError: Cannot read property 'prototype' of undefined
File: "file:///data/data/com.nastc.app/files/app/tns_modules/tns-core-
modules/ui/core/properties/properties.js, line: 461, column: 33

I worked with Brad on this; I can shed a little light on things we tried to isolate the issue:

  • We delete app off phone each time
  • We attempted to use the Android-Runtimes@next as well as the @latest version
  • We attempted to use both tns-core-modules 3.0 and 3.0.1
  • We compared his 3.0.0 tns-core-modules and 3.0.0 tns-core-modules-widgit to my core-modules & widget (identical)
  • We nuked the /data/local/tmp/<app-name> and then manually do a adb install app.apk from the build folder, to make sure livesync couldn't be causing any issues.
  • We deleted the snapshot plugin

This was done on the Windows platform.

I have a couple more ideas; but we already spent a couple hours trying the above...

I'm running into the same thing:

***** Fatal JavaScript exception - application has been terminated. *****
Native stack trace:
1   0x10921729c -[TNSRuntime executeModule:referredBy:]
2   0x1053a8cd0 main
3   0x10b73865d start
4   0x1
JavaScript stack trace:
1   @file:///app/tns_modules/tns-core-modules/ui/core/properties/properties.js:461:34
JavaScript error:
file:///app/tns_modules/tns-core-modules/ui/core/properties/properties.js:461:34: JS ERROR TypeError: undefined is not an object (evaluating 'cls.prototype')

I took a look at file:///app/tns_modules/tns-core-modules/ui/core/properties/properties.js and it's failing on a property named minWidth... a string that is nowhere to be found in my codebase.

@briandilley - A couple questions that might help out the NS Team.

  1. Windows, Mac or Linux
  2. Android OS version
  3. Real device or Emulator
  4. Type of real device or emulator type
  1. Mac
  2. Happens on iOS and Android - latest versions
  3. happens on everything (except for android emulator, i don't use that)
  4. iPhone 6s, Google Pixel, All iOS simulators that i've tried
  1. Linux
  2. Android 7.1.1
  3. Real device
  4. OnePlus 3T

In my case, it worked on:

  1. Linux
  2. Android 5.1.1
  3. Real device
  4. Nexus 4

But I would take the "worked" part with a grain of salt, as it worked intermittently on my OnePlus as well, but very briefly.

Hey guys, I think we found what causes the issue. But, still wondering what is the best way to fix it.

The crash occurs on this line. It seems the Style object passed to the register call is undefined which may happen if there was a circular require and the Style type is still not initialised when the register call is executed.

The problem is that in NS 2.5 the ui/style was a file and in NS 3.0 it is a folder with a package.json. If have installed a 2.5 version and now upgrade to 3.0 the old style.js file will remain on the device and will get loaded instead of the file in the folder. It will then cause the circular dependency issue described before.

We are still thinking of ways to prevent such issues in the future.

@vakrilov thanks for the input here. I'm trying to understand the mention of 'file will remain on the device' ๐Ÿ˜„ If I ran adb shell rm /data/local/tmp/com.whatever.app/* -rR then it should have been deleted. Also uninstalling the app along with removing the directory and files, where else would the file exist? I'd like to delete it and test this solution out so I can get the app moving again on my phone ๐Ÿ˜„ so if you know another temp directory to check on android that might help me get moving forward.

@vakrilov; I have to echo what Brad said; while working with him last night -- he de-installed the app; and we nuked the /data/local/tmp/nsappname folder on the phone to eliminate any potential livesync issues.

I'm not sure HOW that file can exist still anywhere. In addition I had him do a npm r tns-core-modules --save and a npm i [email protected] --save and then nuke his platforms folder. So a fully clean app should have been built. And I had him send me a copy of his tns-core-modules and did a file compare across his directories to a brand new created app; and it didn't show any "extra" files in the tns-core-modules. (I just double checked my tns-core-modules, and I have no style.js file either, since it was a clean created 3.0 app -- windiff would have showed any extra or missing files also).

And finally, this doesn't make that much sense, the same app works fine for Brad on all three of his Android emulators; and only fails on a real android device. If a file was left over on his computer; the same app should be crashing on all three of his emulators in addition to his real device. And by de-installing the app on his phone, that file shouldn't exist on his real device either...

Are there any other places the Telerik may cache livesync info in 3.0? That "might" explain why it keeps failing on some devices if there is another livesync location that I'm unaware of... In Brads case we nuked the /data/local/tmp/ folder, so if that is the only location; it should be gone...

@bradmartin and @NathanaelA I'm also not sure if there are any other places where app files might be cached. @Pip3r4o might have an idea about that. One thing you might try to do is to manually clear applications cache from settings->app->[myApp]->clear cache and then de-installing it (long shot).

There is a possibility that these are two separate issues. I concluded it is the sstyles.js issue by looking at the original stack trace reported by @surdu (line 33 here). The path to the file in NS 3.0 should be /ui/styling/style/style.js instead of /ui/styling/style.js. You can check if you are getting the same stack-trace or different one.

Thanks @vakrilov - I haven't circled back to the app yet. I'll look around and see what's happening on my end and if I can give some help on this issue.

I decided to do a quick test, still no solid fix but I can get the app to work with the following steps:

  • install via tns run or adb install (doesn't matter as that's not an issue)
  • launch the app and ui/styling/style.js in the stacktrace
  • Close the app
  • Open settings > apps > app > clear cache and app data
  • launch the app and it works

This is on my phone that I have to do this, on 5 different geny emulators no issue.

I can confirm the app runs successfully if I perform the CLEAR DATA (clears app data and the cache) under app/storage on my device @vakrilov. If I only use the CLEAR CACHE button in storage it does not fix it. I can then use the app as expected. Kill the process, reopen and it runs fine. Once I do tns run or install the .apk in the platforms/build... it will crash on launch again with the style.js error.

@briandilley , @surdu , @woozie - you still seeing this? If so, does the steps above ^^ from my comment help fix it on any device/emulator that the app crashes on?

K. @NathanaelA can chime in with more info but this works:

  • Uninstall the app from device
  • Enable airplane mode
  • execute tns run android or install via adb
    All works fine ๐ŸŽ‰
    Not a solution but it works for whatever reason airplane mode disables something.

here
inkedscreenshot_20170529-131606_li

@NathanaelA can comment on the findings but this explains why it happens. I've tested numerous times and this also explains why airplane mode works - no network = no restoring previous app state

This also brings up a major issue - I just tried updating another app from 2.5 to 3+ and have crashes thrown in the stacktrace from platform.js when it shouldn't be. I'll test this airplane mode/backup on it and confirm if that fixes it. Hope this info helps @vakrilov @tsonevn

@vakrilov - Ok, @bradmartin is such a trooper; he spent a couple hours doing more tests for me to try and narrow it down and we believe we found the cause. This is something the team MUST fix, as this will affect a large number of people/customers in the wild.

The cause is as @vakrilov suspected from the call stack, a style.js file is getting added to the app; however the responsible party is not who we would expect. I was thinking that LiveSync was somehow re-syncing the tns-core-modules somehow from a old version...

After trying to duplicate the issue on my own device (and failing) and Brad having issues duplicating it in another app; and scanning the android runtime source code for all sync locations and finding out that "clear data" fixes it. And the majority of the issues are only on real devices. I realized that maybe I was thinking sync in too small of a view. Majority of our emulators are NOT tied to a google account so we would never see it...

So I had Brad try the Airplane mode; and the app worked fine. Bingo, that confirmed it was an external sync that is breaking it. Long story short Google restores your settings on a re-install of the app; guess what is part of those settings.. The /files/ folder -- Yeah, you can probably see the implication of why I believe this is a nasty issue; as the majority of REAL devices will be connected to a Google account will have this setting defaulted to ON. (See brads screen shots above).

(As an aside, this might also be the answer to the issue that has been long running about why AppSettings seems to re-appear with invalid data. #2633 & #2061)

@NathanaelA we are aware of it, as we are also aware now of its severity. The reason being that previous application javascript files are not removed from the data/data/app/files directory, but instead replaced, and we might have a fix for that, so that it doesn't happen when updating apps from the store.

I was curious if it would happen when updating from play store. Or if a
version bump on the Android side would prevent it. If so, it's not a
doomsday issue :) but a pain to figure out and develop against. If bumping
the release version on the play store doesn't cause the sync when
reinstalling that would be good. I can try later with a release build on my
phone to see if that prevents it from syncing. If so, it's not end of the
world like I said, just a headache to track down for developing :) thanks
as always for staying on top of things Peter

On Mon, May 29, 2017, 2:00 PM Peter Kanev notifications@github.com wrote:

@NathanaelA https://github.com/nathanaela we are aware of it, as we are
also aware now of its severity. The reason being that previous application
javascript files are not removed from the data/data/app/files directory,
but instead replaced, and we might have a fix for that, so that it doesn't
happen when updating apps from the store.

โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/NativeScript/NativeScript/issues/4137#issuecomment-304715786,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFulhARI4NYY5hhQeNn-hxZXqbMVCDPQks5r-xWwgaJpZM4NTU2u
.

@Pip3r4o - Awesome to know you are now aware of the severity. :+1:

But please remember this is one other use case that you might not be aware/thinking of, that we Brad & I discovered was the cause on his android 7 device. If the client de-install's the app; (so the app is not present anymore), then freshly installs 3.0 version of the app; the Google Application BACKUP system will automatically restore application data and put back the 2.x "style.js" file back in the /files/tns-modules/ui folder causing a fresh CLEAN 3.0 app to crash. The app will work great on any device that doesn't have a backup (or the backup system is off).

Another app I've updated from 2.5 to 3+ does not get hit with this issue. It could be it's not synced with my google account. Just wanted to throw that info out there ๐Ÿ˜„ - I can, however, consistently get the other updated app the crash when running when my google sync is active. Once I disable sync the 3.0 update works great.

@Pip3r4o & @vakrilov - This might be very useful for you guys:
https://developer.android.com/guide/topics/data/autobackup.html

This issue effects is Android 6.0 devices and up.

Two possible solutions in http://fluentreports.com/blog/?p=516

@Pip3r4o @vakrilov - my initial tests confirm that setting allowBackup=false in the manifest will prevent the sync restoring the app. Anyone attempting that will need to add tools to manifest and the appropriate replace statement on the application node in the Manifest, I believe the core-widgets manifest in the .aar has allowBackup=true so have to replace it. So this could be a decent solution for users upgrading from 2x to 3. Disable the sync for a period, and then in a point release enable sync in the manifest. Not elegant by any means but if in a pinch for time that should work. I haven't tested @NathanaelA other solution yet, will try shortly.

Okay - tested and confirmed that checking and deleting the file before any import/require in app.ts/js does indeed work. It's just not as simple and I don't think I'd use that option personally. I'll prob disable the backup and publish an update - wait a few weeks or month and then enable it once all (or most)l users have updated. This would be a decent approach depending on the size of app installs.

@bradmartin the backup restore logic would not fire if just updating the application from the store, but the android runtime still wouldn't know that it needs to remove previous /files files that are no longer part of the project.

A little naive solution - I've made a patch that will wipe out all sources from files/app before dropping off everything from the apk, that should ensure that there are no left-overs that are no longer used on your device. The wipe-extraction logic is triggered every time a new version is downloaded, at startup - should previous state of the app cache be restored - it will be completely replaced by that of the new package.

The fix was provided in the android-runtime by @Pip3r4o's PR(NativeScript/android-runtime#771)
Will be available in NativeScript 3.1.

Hey guys, we're on 3.0.1 and just to add to this convo... I have 2 Galaxy S7 users who are installing the app from the play store and not seeing any of the app changes.

Got a client also with a Galaxy S7 and I've had to disabled backup in the manifest to ship an .apk for testing. It's been a rough couple of days, I thought the client was hopeless until I found other S7 users not able to update. My Droid Turbo 2 is fixed with Peter's runtime fix but seems the Galaxy S7 has a different approach needed.

@bradmartin @sitefinitysteve I'll try to get my hands on a Galaxy S7 and see what gives.

I'm getting this issue as well. Is there a fix for this?

I'm having the same issue.

let mobileNumber = 639082150652
applicationSettings.setNumber('memberMobile', mobileNumber)
console.log(mobileNumber)
console.log(applicationSettings.getNumber('memberMobile'))
// outputs
639082150652
639082168320

here's my NS version
"nativescript-telerik-ui-pro": "^3.1.4",
"nativescript-theme-core": "~1.0.2",
"tns-core-modules": "~3.2.0"

running on windows 10 / genymotion android 6 and 7

All i had to do was delete the app on my phone and let it re-install, try it out...cheers

I am also getting exact same error.
I can run my nativescript app on ios without any issues.
But when I run tns run android, the app starts and shows this message on device screen.

I have tried this solution by @bradmartin:
1) completely unistalled app from android phone
2) Started airplane mode
3) Ran the app again by giving command tns run android

I still see same error (only for android).

Hi @surabhiu,
Could you provide more info about your environment(CLI, tns-core-modules, tns-android versions)?
In the meantime, you could try removing the application with adb command adb uninstall <application _name> and ti try again building it with tns run android.

@tsonevn,
This issue has been resolved for me. Thanks.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lscown picture lscown  ยท  163Comments

Dimitrievskislavcho picture Dimitrievskislavcho  ยท  51Comments

NickIliev picture NickIliev  ยท  58Comments

NathanaelA picture NathanaelA  ยท  92Comments

lscown picture lscown  ยท  58Comments