NativeScript / nativescript-angular

Integrating NativeScript with Angular
http://docs.nativescript.org/angular/tutorial/ng-chapter-0
Apache License 2.0
1.21k stars 241 forks source link

tns preview crashed on shared code #1562

Closed brain-kode closed 6 years ago

brain-kode commented 6 years ago

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

Describe the bug tns preview command crash in an empty angular shared code project

To Reproduce tns preview

Executing before-shouldPrepare hook from 
myapp/hooks/before-shouldPrepare/nativescript-dev-webpack.js
Skipping prepare.
Successfully synced changes for platform android.
LOG from device ASUS_X00ID: An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.preview/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: 
Calling js method onCreate failed

TypeError: Cannot read property 'create' of undefined
File: "file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/builder/builder.js, line: 75, column: 14

StackTrace: 
    Frame: function:'', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 75, column: 15
    Frame: function:'FrameBase.navigate', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 118, column: 30
    Frame: function:'ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 832, column: 30
    Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 691, column: 14
    Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 20, column: 25

    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:159)
    at android.app.ActivityThread.main(ActivityThread.java:6139)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: com.tns.NativeScriptException: 
Calling js method onCreate failed

TypeError: Cannot read property 'create' of undefined
File: "file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/builder/builder.js, line: 75, column: 14

StackTrace: 
    Frame: function:'', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 75, column: 15
    Frame: function:'FrameBase.navigate', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 118, column: 30
    Frame: function:'ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 832, column: 30
    Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 691, column: 14
    Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 20, column: 25

    at com.tns.Runtime.callJSMethodNative(Native Method)
    at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116)
    at com.tns.Runtime.callJSMethodImpl(Runtime.java:996)
    at com.tns.Runtime.callJSMethod(Runtime.java:983)
    at com.tns.Runtime.callJSMethod(Runtime.java:967)
    at com.tns.Runtime.callJSMethod(Runtime.java:959)
    at com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:18)
    at android.app.Activity.performCreate(Activity.java:6759)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
    ... 9 more
tsonevn commented 6 years ago

Hi @brain-kode, We have tested the scenario while using the tns preview command with a shared project, however, we were unabled to reproduce a similar issue. Regarding that, can you provide a sample project, which can be used for recreating the issue?

Note: Using lazy-loaded modules in the project can lead to an issue while staring the project in the preview app. Make sure that you are not using similar modules.

brain-kode commented 6 years ago

Hi @tsonevn, thank you for your fast reply. This is what I get from compilation of a blank shared project in ubuntu 18.04

Plugin core-js is not included in preview app on device 8d56fdb5-1dfd-4889-8c0c-64e7a7bc70bd and will not work.
Start syncing changes for platform android.
Copying template files...
Platform android successfully added. v5.0.0-rc-2018-10-18-172901-01
Executing before-shouldPrepare hook from /home/gmat/Lavoro/Perso/Test/my-app/hooks/before-shouldPrepare/nativescript-dev-webpack.js
Executing before-prepare hook from /home/gmat/Lavoro/Perso/Test/my-app/hooks/before-prepare/nativescript-dev-typescript.js
Hook skipped because either bundling or livesync is in progress.
Preparing project...
Executing before-prepareJSApp hook from /home/gmat/Lavoro/Perso/Test/my-app/hooks/before-prepareJSApp/nativescript-dev-webpack.js
Project successfully prepared (android)
Executing after-prepare hook from /home/gmat/Lavoro/Perso/Test/my-app/hooks/after-prepare/nativescript-dev-webpack.js
Successfully synced changes for platform android.
LOG from device ASUS_X00ID: com.tns.NativeScriptException: Application entry point file not found. Please specify the file in package.json otherwise make sure the file index.js or bootstrap.js exists.\nIf using typescript make sure your entry point file is transpiled to javascript.
    at com.tns.Module.bootstrapApp(Module.java:311)
    at com.tns.Runtime.run(Runtime.java:544)
    at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1025)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5423)
    at android.app.ActivityThread.-wrap2(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:159)
    at android.app.ActivityThread.main(ActivityThread.java:6139)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: com.tns.NativeScriptException: Failed to find module: "./", relative to: app//
    at com.tns.Module.resolvePathHelper(Module.java:146)
    at com.tns.Module.bootstrapApp(Module.java:309)
    ... 12 more
tsonevn commented 6 years ago

Hi @brain-kode, After reviewing the error log, I notice that the following warning was printed Plugin core-js is not included in preview app on device. Keep in mind that using an externaл plugin (such as core-js) in the preview app is not supported. Here is a list of the plugins, which are included in the Preview app:

"kinvey-nativescript-sdk": "3.11.7",
  "nativescript-accelerometer": "2.0.1",
  "nativescript-angular": "6.1.0",
  "nativescript-background-http": "3.3.0",
  "nativescript-camera": "4.0.2",
  "nativescript-fresco": "5.0.0",
  "nativescript-geolocation": "4.3.0",
  "nativescript-imagepicker": "6.0.4",
  "nativescript-intl": "3.0.0",
  "nativescript-iqkeyboardmanager": "1.3.0",
  "nativescript-social-share": "1.5.1",
  "nativescript-theme-core": "1.0.4",
  "nativescript-ui-autocomplete": "3.9.0",
  "nativescript-ui-calendar": "3.8.1",
  "nativescript-ui-chart": "3.9.0",
  "nativescript-ui-dataform": "3.7.3",
  "nativescript-ui-gauge": "3.7.1",
  "nativescript-ui-listview": "3.7.0",
  "nativescript-ui-sidedrawer": "4.3.0",

If you need using a plugin, which is not included, you should deploy the app on the device using local build.

brain-kode commented 6 years ago

Hi @tsonevn , I didn't install any plugin on my app. I just created a new app with ng new --collection=@nativescript/schematics --name=my-app --shared and then I did tns preview

brain-kode commented 6 years ago

core-js is added in package.json when I create a new project. Even if I removed it, I still get the same error.

tsonevn commented 6 years ago

Hi @brain-kode, Thank you for your further investigation. I would suggest waiting for the official release of NativeScript (v 5.0). We will publish a new preview app, with the latest available dependencies versions (latest tns-core-modules, nativescript-angular, etc...). Currently, you are using a preview app, which at this time depends on NativeScript 4.2, where some of the changes made in 5.0 are not included. If you are facing a problem after the 5.0 release, you can always open a new issue. Also, keep in mind that tns preview is an experimental feature and can be used only for making some test application. For developing a more complex app, please use the local NativeScript setup for building a project or SideKick cloud builds.

chamikasandamal commented 5 years ago

It seems tns preview --bundle will solve this issue

crowmagnumb commented 5 years ago

It seems tns preview --bundle will solve this issue

Thank you!

omickelsen commented 5 years ago

tns preview --bundle worked for me