Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--env.uglify breaks app #4574

Closed
yringler opened this issue Apr 30, 2019 · 3 comments
Closed

--env.uglify breaks app #4574

yringler opened this issue Apr 30, 2019 · 3 comments
Assignees
Labels

Comments

@yringler
Copy link

yringler commented Apr 30, 2019

Environment
Output of tns info:
√ Component nativescript has 5.3.4 version and is up to date.
√ Component tns-core-modules has 5.3.1 version and is up to date.
√ Component tns-android has 5.3.1 version and is up to date.

Describe the bug
I observed that my app would often fail suddenly and unexpectedly.
I further observed (edit: before I tried installing uglify as a dev dependency) that this only happen when I passed in --env.uglify.
Later, [edit] after manually installing uglifyjs-webpack-plugin as a dev dependency, which I presume got me the latest version, I started seeing the following error in my builds:

ERROR in vendor.js from UglifyJs
Unexpected token: keyword «const» [vendor.js:89845,46]

ERROR in bundle.js from UglifyJs
Unexpected token: name «applicationCheckPlatform», expected: punc «;» [bundle.js:574,12]

I think these were always errors, just that they weren't being printed in the default bundled version.
I believe this only happened after I updated my webpack/config.
Perhaps it is no longer properly transpiling to es5?
I confirmed that the vendor.js file has multiple occurances of the const keyword.

To Reproduce
Uglification errors (breaks build):
git clone https://github.com/yringler/rabbi-gordon-audio
git checkout 77bbe9b23e0796cf8d53d2a1c31ec9ff1a00d3c3
tns run android --bundle --env.uglify

App runs, with errors:
git clone https://github.com/yringler/rabbi-gordon-audio
git checkout f2af3f495d229b38cdd1e3bd7d48089a61708d2e
tns run android --bundle --env.uglify
The app should crash. Cancel, then run again should show errors.

Expected behavior
Uglification should not make the app unstable.

Sample project
https://github.com/yringler/rabbi-gordon-audio

Additional context
I'm using angular.

On master, I "refreshed", copying over my code to a clean tns app. This "clean" app, with some older versions, seems to work fine.
I tried updating from there on a new branch(https://github.com/yringler/rabbi-gordon-audio/tree/17-try-upgrade), but am again getting errors.
I'm still investigating exact replication.

Here is a sample log with error which occurs when run with uglification

Successfully synced application org.nativescript.RabbiGordonAudio on device ZY2247X89T.
JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
JS: The following files were deleted: ["/data/user/0/org.nativescript.RabbiGordonAudio/files/lessons-cache/0rdon1556625600.mp3","/data/user/0/org.nativescript.RabbiGordonAudio/files/lessons-cache/1rdon1556625600.mp3","/data/user/0/org.nativescript.RabbiGordonAudio/files/lessons-cache/2rdon1556625600.mp3"]
System.err: com.tns.NativeScriptException:
System.err: Calling js method onCreateView failed
System.err:
System.err: Error: java.lang.NoSuchMethodError: no non-static method "Landroid/widget/TextView;.setText()I"
System.err:     com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1203)
System.err:     com.tns.Runtime.callJSMethodImpl(Runtime.java:1083)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:1070)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:1050)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:1042)
System.err:     com.tns.FragmentClass.onCreateView(FragmentClass.java:53)
System.err:     android.support.v4.app.Fragment.performCreateView(Fragment.java:2439)
System.err:     android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
System.err:     android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
System.err:     android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
System.err:     android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
System.err:     android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
System.err:     android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
System.err:     android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
System.err:     android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
System.err:     android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
System.err:     android.os.Handler.handleCallback(Handler.java:789)
System.err:     android.os.Handler.dispatchMessage(Handler.java:98)
System.err:     android.os.Looper.loop(Looper.java:164)
System.err:     android.app.ActivityThread.main(ActivityThread.java:6695)
System.err:     java.lang.reflect.Method.invoke(Native Method)
System.err:     com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
System.err:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:772)
System.err: File: "file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js, line: 1, column: 996347
System.err:
System.err: StackTrace:
System.err:     Frame: function:'n._setNativeText', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 996348
System.err:     Frame: function:'n.(anonymous function)', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 990953
System.err:     Frame: function:'w', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 935194
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 934557
System.err:     Frame: function:'t.onResumeNativeUpdates', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1396191
System.err:     Frame: function:'t._resumeNativeUpdates', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1388823
System.err:     Frame: function:'t.onLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1387979
System.err:     Frame: function:'n.onLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 771331
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389568
System.err:     Frame: function:'t.callFunctionWithSuper', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389376
System.err:     Frame: function:'t.callLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389504
System.err:     Frame: function:'t.loadView', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1392205
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1388039
System.err:     Frame: function:'t.eachChildView', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1482814
System.err:     Frame: function:'r.eachChild', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1265040
System.err:     Frame: function:'t.onLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1388015
System.err:     Frame: function:'n.onLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 771331
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389568
System.err:     Frame: function:'t.callFunctionWithSuper', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389376
System.err:     Frame: function:'t.callLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389504
System.err:     Frame: function:'t.loadView', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1392205
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1388039
System.err:     Frame: function:'t.eachChildView', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1482814
System.err:     Frame: function:'r.eachChild', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1265040
System.err:     Frame: function:'t.onLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1388015
System.err:     Frame: function:'n.onLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 771331
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389568
System.err:     Frame: function:'t.callFunctionWithSuper', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389376
System.err:     Frame: function:'t.callLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389504
System.err:     Frame: function:'t.loadView', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1392205
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1388039
System.err:     Frame: function:'t.eachChildView', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1482814
System.err:     Frame: function:'r.eachChild', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1265040
System.err:     Frame: function:'t.onLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1388015
System.err:     Frame: function:'n.onLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 771331
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389568
System.err:     Frame: function:'t.callFunctionWithSuper', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389376
System.err:     Frame: function:'t.callLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389504
System.err:     Frame: function:'t.loadView', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1392205
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1388039
System.err:     Frame: function:'t.eachChildView', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 985144
System.err:     Frame: function:'t.eachChildView', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1513938
System.err:     Frame: function:'r.eachChild', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1265040
System.err:     Frame: function:'t.onLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1388015
System.err:     Frame: function:'n.onLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 771331
System.err:     Frame: function:'t.onLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1009480
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389568
System.err:     Frame: function:'t.callFunctionWithSuper', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389376
System.err:     Frame: function:'t.callLoaded', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1389504
System.err:     Frame: function:'t.loadView', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1392205
System.err:     Frame: function:'t._addViewCore', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1392141
System.err:     Frame: function:'t._addView', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1391817
System.err:     Frame: function:'e.onCreateView', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 905305
System.err:     Frame: function:'n.onCreateView', file:'file:///data/data/org.nativescript.RabbiGordonAudio/files/app/vendor.js', line: 1, column: 1741582
System.err:
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1203)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1083)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1070)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1050)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1042)
System.err:     at com.tns.FragmentClass.onCreateView(FragmentClass.java:53)
System.err:     at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439)
System.err:     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
System.err:     at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
System.err:     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
System.err:     at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
System.err:     at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
System.err:     at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
System.err:     at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
System.err:     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
System.err:     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
System.err:     at android.os.Handler.handleCallback(Handler.java:789)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:98)
System.err:     at android.os.Looper.loop(Looper.java:164)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6695)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:772)
System.err: Caused by: java.lang.NoSuchMethodError: no non-static method "Landroid/widget/TextView;.setText()I"
System.err:     ... 24 more
@miroslavaivanova
Copy link
Contributor

@yringler the latest version of nativescript-dev-webpack is handling this uglifyjs-webpack-plugin and it should not be explicitly installed as dev dependency.
To resolve this error you can uninstall uglifyjs-webpack-plugin, remove node_modules and package-lock.json.

  1. npm un uglifyjs-webpack-plugin
  2. rm -rf node_modules/ package-lock.json
  3. npm i
  4. tns run android --bundle --env.uglify

In our next version of nativescript-dev-webpack we switch from UglifyJS to Terser. If you prefer to use it please install next version of nativescript-dev-webpack and run upgrade script .

@yringler
Copy link
Author

yringler commented May 3, 2019

it should not be explicitly installed as dev dependency

Before I installed it as dev dependency, I was getting runtime errors, but only when uglification was enabled. I installed it as dev dependency to experiment.
It's possible it was coincidental, (I later found in my code a possible source of errors), but I tested with and without uglification as thoroughly as I could.

In our next version of nativescript-dev-webpack we switch from UglifyJS to Terser.

I will definitely try that out. Thrilled that switching to an es6 uglifier!

yringler added a commit to yringler/rabbi-gordon-audio that referenced this issue May 3, 2019
@yringler
Copy link
Author

yringler commented May 3, 2019

I tried nativescript-dev-webpack@next and nativescript-dev-webpack@latest on my current master and everything was fine.
It seems that the older version of my app was somehow causing intermittent problems 🙈
Everything looks good now. Sorry, seems it was my bug.
Thank you, though.

@yringler yringler closed this as completed May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants