Exception in Nativescript 3.3.0 after upgrading


#1

Hi there, I just tried to upgrade my project to Nativescript 3.3.0 and after running:

npm install -g nativescript
tns update
tns plugin update

I get this error when the app is launched:

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: Invalid provider - only instances of Provider and Type are allowed, got: [object Object]
System.err: File: "file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js, line: 2118, column: 12
System.err:
System.err: StackTrace:
System.err:     Frame: function:'ZoneAwareError', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js', line: 993, column: 33
System.err:     Frame: function:'invalidProviderError', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 1317, column: 12
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2118, column: 19
System.err:     Frame: function:'_normalizeProviders', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2107, column: 15
System.err:     Frame: function:'resolveReflectiveProviders', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2058, column: 39
System.err:     Frame: function:'ReflectiveInjector.resolve', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2287, column: 16
System.err:     Frame: function:'ReflectiveInjector.resolveAndCreate', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2319, column: 79
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 4357, column: 51
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 4354, column: 17
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 4354, column: 17
System.err:     Frame: function:'platformNativeScriptDynamic', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/nativescript-angular/platform.js', line: 41, column: 62
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/main.js', line: 6, column: 12
System.err:     Frame: function:'require', file:'', line: 1, column: 266
System.err:
System.err:
System.err: Error: Invalid provider - only instances of Provider and Type are allowed, got: [object Object]
System.err: File: "<unknown>, line: 1, column: 265
System.err:
System.err: StackTrace:
System.err:     Frame: function:'ZoneAwareError', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js', line: 993, column: 33
System.err:     Frame: function:'invalidProviderError', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 1317, column: 12
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2118, column: 19
System.err:     Frame: function:'_normalizeProviders', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2107, column: 15
System.err:     Frame: function:'resolveReflectiveProviders', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2058, column: 39
System.err:     Frame: function:'ReflectiveInjector.resolve', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2287, column: 16
System.err:     Frame: function:'ReflectiveInjector.resolveAndCreate', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2319, column: 79
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 4357, column: 51
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 4354, column: 17
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 4354, column: 17
System.err:     Frame: function:'platformNativeScriptDynamic', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/nativescript-angular/platform.js', line: 41, column: 62
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/main.js', line: 6, column: 12
System.err:     Frame: function:'require', file:'', line: 1, column: 266
System.err:
System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5406)
System.err:     at android.app.ActivityThread.-wrap2(ActivityThread.java)
System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
System.err:     at android.os.Looper.loop(Looper.java:154)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6119)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
System.err: Caused by: com.tns.NativeScriptException:
System.err:
System.err: Error calling module function
System.err:
System.err: Error: Invalid provider - only instances of Provider and Type are allowed, got: [object Object]
System.err: File: "file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js, line: 2118, column: 12
System.err:
System.err: StackTrace:
System.err:     Frame: function:'ZoneAwareError', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js', line: 993, column: 33
System.err:     Frame: function:'invalidProviderError', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 1317, column: 12
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2118, column: 19
System.err:     Frame: function:'_normalizeProviders', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2107, column: 15
System.err:     Frame: function:'resolveReflectiveProviders', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2058, column: 39
System.err:     Frame: function:'ReflectiveInjector.resolve', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2287, column: 16
System.err:     Frame: function:'ReflectiveInjector.resolveAndCreate', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2319, column: 79
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 4357, column: 51
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 4354, column: 17
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 4354, column: 17
System.err:     Frame: function:'platformNativeScriptDynamic', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/nativescript-angular/platform.js', line: 41, column: 62
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/main.js', line: 6, column: 12
System.err:     Frame: function:'require', file:'', line: 1, column: 266
System.err:
System.err:
System.err: Error: Invalid provider - only instances of Provider and Type are allowed, got: [object Object]
System.err: File: "<unknown>, line: 1, column: 265
System.err:
System.err: StackTrace:
System.err:     Frame: function:'ZoneAwareError', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js', line: 993, column: 33
System.err:     Frame: function:'invalidProviderError', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 1317, column: 12
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2118, column: 19
System.err:     Frame: function:'_normalizeProviders', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2107, column: 15
System.err:     Frame: function:'resolveReflectiveProviders', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2058, column: 39
System.err:     Frame: function:'ReflectiveInjector.resolve', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2287, column: 16
System.err:     Frame: function:'ReflectiveInjector.resolveAndCreate', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 2319, column: 79
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 4357, column: 51
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 4354, column: 17
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/@angular/core/bundles/core.umd.js', line: 4354, column: 17
System.err:     Frame: function:'platformNativeScriptDynamic', file:'file:///data/data/com.mycompany.myapp/files/app/tns_modules/nativescript-angular/platform.js', line: 41, column: 62
System.err:     Frame: function:'', file:'file:///data/data/com.mycompany.myapp/files/app/main.js', line: 6, column: 12
System.err:     Frame: function:'require', file:'', line: 1, column: 266
System.err:
System.err:     at com.tns.Runtime.runModule(Native Method)
System.err:     at com.tns.Runtime.runModule(Runtime.java:530)
System.err:     at com.tns.Runtime.run(Runtime.java:522)
System.err:     at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
System.err:     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403)
System.err:     ... 8 more
ActivityManager: Process com.mycompany.myapp (pid 13850) has died
ActivityManager: cleanUpApplicationRecord -- 13850
13:26:51 - Compilation complete. Watching for file changes.

My package.json looks like this:

{
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "nativescript": {
    "id": "com.mycompany.myapp",
    "tns-android": {
      "version": "3.3.0"
    },
    "tns-ios": {
      "version": "3.3.0"
    }
  },
  "scripts": {
    "lint": "tslint \"app/**/*.ts\""
  },
  "dependencies": {
    "@angular/animations": "4.4.6",
    "@angular/common": "4.4.6",
    "@angular/compiler": "4.4.6",
    "@angular/core": "4.4.6",
    "@angular/forms": "4.4.6",
    "@angular/http": "4.4.6",
    "@angular/platform-browser": "4.4.6",
    "@angular/router": "4.4.6",
    "nativescript-angular": "^4.4.1",
    "nativescript-couchbase": "^1.0.18",
    "nativescript-loading-indicator": "^2.4.0",
    "nativescript-pro-ui": "^3.2.0",
    "nativescript-theme-core": "^1.0.4",
    "reflect-metadata": "0.1.10",
    "rxjs": "5.5.2",
    "tns-core-modules": "^3.3.0",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "babel-traverse": "6.4.5",
    "babel-types": "6.4.5",
    "babylon": "6.4.5",
    "codelyzer": "3.2.2",
    "lazy": "1.0.11",
    "nativescript-dev-sass": "^1.3.2",
    "nativescript-dev-typescript": "0.5.1",
    "node-sass": "4.5.3",
    "tslint": "5.8.0",
    "typescript": "2.5.3"
  }
}

This is my app.module.ts:

import { NgModule, NgModuleFactoryLoader, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { NativeScriptHttpModule } from "nativescript-angular/http";
import { NSModuleFactoryLoader } from "nativescript-angular/router";

import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";

import { Database } from "./providers/database/database";
import { LoadingIndicator } from "nativescript-loading-indicator";

@NgModule({
    bootstrap: [
        AppComponent
    ],
    imports: [
        NativeScriptModule,
        AppRoutingModule,
        NativeScriptHttpModule
    ],
    declarations: [
        AppComponent
    ],
    providers: [
        { provide: NgModuleFactoryLoader, useClass: NSModuleFactoryLoader },
        Database,
        LoadingIndicator
    ],
    schemas: [
        NO_ERRORS_SCHEMA
    ]
})
export class AppModule { }

Any ides whats going on?

Thanks!


#2

Your problem area is here. You are passing LoadingIndicator as a provider, which it is not. Items that are marked with @Injectable() are provider-based classes. This appears to be a 3rd party plugin.

Hence the error:

System.err: Error: Invalid provider - only instances of Provider and Type are allowed, got: [object Object]


#3

Hi Sean, thanks for the reply, but I have already tried that, right now my providers looks like this:

providers: [
    { provide: NgModuleFactoryLoader, useClass: NSModuleFactoryLoader },
    Database
],

And I am still getting this error. :frowning: :frowning: :frowning:


#4

Is Database actually a provider? Based on your original question, you explain the scenario as only upgrading NativeScript and running into these problems. Is that not the case? Did you make manipulations or add additional code outside of the scope of just upgrading?


#5

Hi Sean, thanks again for your reply.

I finally decided to delete the folder /hooks and /node_modules then recompile again and it worked.

I made sure to tns platform remove android and then tns run android after delete those folders. Seems that its recommended to delete /node_modules folder after upgrade.

Thanks for your replies, I hope it could help someone in the future.