1

I had a web application using Angular version 7 and wanted to do code-sharing from NativeScript. After installing nativescript and the schemantics successfully, I tried to run tns run android --bundle.

The STRANGEST of all is that when I run the application for the first time, it shows the error. When I change smt and then save it with hot reloading feature, it is shown perfectly.

But I am getting this error:

System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.ngsample/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: System.err: Calling js method onCreate failed System.err: System.err: Error: Main entry is missing. App cannot be started. Verify app bootstrap. System.err: File: "file:///data/data/org.nativescript.ngsample/files/app/vendor.js, line: 21913, column: 20 System.err: System.err: StackTrace: System.err: Frame: function:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/org.nativescript.ngsample/files/app/vendor.js', line: 21913, column: 27 System.err: Frame: function:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.ngsample/files/app/vendor.js', line: 21758, column: 14 System.err: Frame: function:'push.../node_modules/tns-core-modules/ui/frame/activity.js.NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.ngsample/files/app/vendor.js', line: 19571, column: 25 System.err: System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913) System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) System.err: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) System.err: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) System.err: at android.os.Handler.dispatchMessage(Handler.java:106) System.err:
at android.os.Looper.loop(Looper.java:193) System.err: at android.app.ActivityThread.main(ActivityThread.java:6669) System.err: at java.lang.reflect.Method.invoke(Native Method) System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) System.err: Caused by: com.tns.NativeScriptException: System.err: Calling js method onCreate failed System.err: System.err: Error: Main entry is missing. App cannot be started. Verify app bootstrap. System.err: File: "file:///data/data/org.nativescript.ngsample/files/app/vendor.js, line: 21913, column: 20 System.err: System.err: StackTrace: System.err: Frame: function:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/org.nativescript.ngsample/files/app/vendor.js', line: 21913, column: 27 System.err: Frame: function:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.ngsample/files/app/vendor.js', line: 21758, column: 14 System.err: Frame: function:'push.../node_modules/tns-core-modules/ui/frame/activity.js.NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.ngsample/files/app/vendor.js', line: 19571, column: 25 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.NativeScriptActivity.onCreate(NativeScriptActivity.java:19) System.err: at android.app.Activity.performCreate(Activity.java:7136) System.err:
at android.app.Activity.performCreate(Activity.java:7127) System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) System.err: ... 11 more Successfully synced application org.nativescript.ngsample on device emulator-5554.

I deleted hooks, platforms, node_modules and webpack.config.js files and installed then again but nothing changed. I also upgrade tns-core-modules, typescript and nativescript-dev-webpack to the latest version. What am I missing?

My package.json file:

{
  "name": "farm-management-ui",
  "description": "The UI for farm management",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "android": "tns run android --bundle",
    "ios": "tns run ios --bundle",
    "mobile": "tns run --bundle",
    "preview": "tns preview --bundle",
    "ng": "ng",
    "start": "ng serve --base-href=/ui/",
    "start-local-prod": "ng serve --base-href=/ui/",
    "start-traci": "ng serve --configuration=traci-dev --base-href=/ui/",
    "build": "ng build --prod --base-href=/ui/",
    "build-traci": "ng build --prod --configuration=traci --base-href=/ui/",
    "test": "ng test --code-coverage=true",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "loco": "node tools/update-localized-strings.js",
    "bundle-report": "webpack-bundle-analyzer dist/stats.json",
    "licenses": "node tools/extract-licenses.js"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/architect": "^0.13.9",
    "@angular-devkit/build-optimizer": "^0.13.9",
    "@angular-devkit/build-webpack": "^0.13.9",
    "@angular-devkit/core": "^7.3.9",
    "@angular/animations": "^7.2.0",
    "@angular/cdk": "^7.2.1",
    "@angular/common": "7.2.0",
    "@angular/compiler": "7.2.0",
    "@angular/core": "7.2.0",
    "@angular/forms": "7.2.0",
    "@angular/http": "7.2.0",
    "@angular/material": "^7.2.1",
    "@angular/platform-browser": "7.2.0",
    "@angular/platform-browser-dynamic": "7.2.0",
    "@angular/router": "7.2.0",
    "@asymmetrik/ngx-leaflet": "^3.0.2",
    "@asymmetrik/ngx-leaflet-draw": "^2.7.1",
    "@asymmetrik/ngx-leaflet-markercluster": "^1.0.0",
    "@bwc/bwc-button": "^2.0.5",
    "@bwc/bwc-footer": "^2.0.2",
    "@bwc/bwc-header": "^4.1.2",
    "@bwc/bwc-input": "^2.2.2",
    "@bwc/bwc-overlay": "^3.0.6",
    "@bwc/bwc-style": "^2.1.0",
    "@inst-iot/bosch-angular-ui-components": "^0.3.20",
    "@nativescript/schematics": "^0.6.0",
    "@ng-bootstrap/ng-bootstrap": "^4.0.1",
    "@ngx-translate/core": "^11.0.1",
    "@ngx-translate/http-loader": "^4.0.0",
    "@schematics/angular": "^7.3.9",
    "@swimlane/ngx-datatable": "^14.0.0",
    "@types/geojson": "^1.0.6",
    "@types/leaflet": "^1.2.6",
    "@types/leaflet.markercluster": "^1.0.3",
    "@types/leaflet.pm": "^0.13.3",
    "@webcomponents/webcomponentsjs": "^2.2.4",
    "angular-2-local-storage": "^1.0.1",
    "bootstrap-daterangepicker": "^3.0.3",
    "bosch-bootstrap": "git+https://products.bosch-si.com/stash/scm/instiot/bosch-bootstrap.git#v4",
    "brace": "^0.10.0",
    "chart.js": "^2.7.2",
    "chartjs-plugin-annotation": "^0.5.7",
    "chartjs-plugin-zoom": "^0.6.6",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.5.1",
    "file-saver": "^1.3.8",
    "flatpickr": "^4.5.7",
    "font-awesome": "^4.7.0",
    "jquery": "^3.3.1",
    "json-formatter-js": "^2.2.0",
    "leaflet": "^1.3.1",
    "leaflet-draw": "^1.0.2",
    "leaflet-easybutton": "^2.3.0",
    "leaflet.markercluster": "^1.3.0",
    "leaflet.pm": "^0.22.0",
    "magic-string": "^0.22.4",
    "moment": "^2.19.4",
    "nan": "^2.14.0",
    "nativescript-angular": "~7.2.0",
    "nativescript-theme-core": "~1.0.4",
    "ng2-ace-editor": "^0.3.3",
    "ng5-slider": "^1.1.3",
    "ngx-clipboard": "^12.1.2",
    "ngx-gallery": "^4.3.0",
    "ngx-toastr": "^10.0.2",
    "ngx-ui-switch": "^6.0.3",
    "popper.js": "^1.13.0",
    "puppeteer": "^1.17.0",
    "reflect-metadata": "~0.1.12",
    "rxjs": "^6.3.3",
    "sass-loader": "^6.0.5",
    "tmp": "0.0.30",
    "tns-core-modules": "^5.4.3",
    "tslib": "^1.9.0",
    "uuid": "^3.3.2",
    "web-animations-js": "^2.3.1",
    "zone.js": "^0.8.27"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.12.4",
    "@angular/cli": "^7.3.9",
    "@angular/compiler-cli": "8.0.0",
    "@angular/language-service": "7.2.0",
    "@nativescript/schematics": "0.6.0",
    "@types/chart.js": "^2.7.18",
    "@types/jasmine": "2.8.6",
    "@types/leaflet-draw": "^0.4.11",
    "@types/node": "^6.0.92",
    "codelyzer": "^4.2.1",
    "https-proxy-agent": "^2.1.1",
    "jasmine-core": "^2.99.1",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "^1.7.1",
    "karma-chrome-launcher": "^2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.4.3",
    "karma-firefox-launcher": "^1.0.1",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-spec-reporter": "0.0.32",
    "license-checker": "^21.0.0",
    "nativescript-dev-webpack": "^0.24.1",
    "node-sass": "^4.12.0",
    "protractor": "~5.1.2",
    "rxjs-tslint": "^0.1.6",
    "style-loader": "^0.23.1",
    "ts-node": "~3.0.4",
    "tslint": "^5.10.0",
    "typescript": "^3.4.5"
  },
  "nativescript": {
    "id": "org.nativescript.ngsample",
    "tns-android": {
      "version": "5.4.0"
    }
  }
}

My main.tns.ts fle:

import { platformNativeScriptDynamic } from 'nativescript-angular/platform';

import { AppModule } from './app/app.module';

platformNativeScriptDynamic().bootstrapModule(AppModule);

My main.ts file:

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
  enableProdMode();
}

document.addEventListener('WebComponentsReady', () => {
  platformBrowserDynamic()
    .bootstrapModule(AppModule, {preserveWhitespaces: false})
    .catch(err => console.log(err));
});
Kathrine Hanson
  • 575
  • 2
  • 10
  • 32

2 Answers2

1

This worked for me...

  • Remove all packages from dependecies and devDependencies in file package.json (only save it in some .txt file, it will required)

  • Run npm i, it will remove all packages from node_modules folder

  • After, return all packages, which was in dependecies and devDependecies, and save

  • Then run again npm i and after you can start your project.

0

Try implementing bootstrap like below. main.ts file

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
  enableProdMode();
}


platformBrowserDynamic().bootstrapModule(AppModule, {preserveWhitespaces: false})
  .catch(err => console.log(err));
  • Hi! Thanks for your reply! Again I am getting the same error... the strange thing is as I said that when I do a change after the first execution, I can see the app. – Kathrine Hanson Jul 04 '19 at 10:32
  • @KathrineHanson Hi, I am getting the same error when there is a missing import in any of the components. Please, verify if there is any code error in your app. – simar.pawar Jul 04 '19 at 11:58
  • Hi simar! Thansk for your reply. You mean the .tns files right? This happens to you only in the beginning because for me only then it happens and then when I do a change, I can see my app. – Kathrine Hanson Jul 04 '19 at 12:07