Skip to content

Crash with scoped package (Can't resolve all parameters for ApplicationModule) #2183

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

Open
armpogart opened this issue Jun 25, 2020 · 6 comments

Comments

@armpogart
Copy link

Environment

  • CLI: 6.7.4
  • Cross-platform modules: 6.5.8
  • Android Runtime: 6.5.1
  • iOS Runtime: 6.5.0
  • Plugin(s):
  • NativeScript-Angular: 8.21.0
  • Angular: 8.2.14

Describe the bug

After creating blank angular template, I have changed package.json to use scoped packages: @nativescript/angular' instead of nativescript-angularand@nativescript/coreinstead oftns-core-modules. Removed node_modules, platformsandhooks folders and reinstalled dependencies. Changed all the imports to use the scoped packages. Running application (tns run android`) causes crash with following error:

System.err: An uncaught Exception occurred on "main" thread.
System.err: Unable to start activity ComponentInfo{org.nativescript.testapp/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
System.err: Error: Can't resolve all parameters for ApplicationModule: (?).
System.err:
System.err: StackTrace:
System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.testapp/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
System.err: Error: Can't resolve all parameters for ApplicationModule: (?).
System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
System.err:     at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:107)
System.err:     at android.os.Looper.loop(Looper.java:214)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:7356)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
System.err: Caused by: com.tns.NativeScriptException: Calling js method onCreate failed
System.err: Error: Can't resolve all parameters for ApplicationModule: (?).
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1286)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1173)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1160)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1138)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1134)
System.err:     at com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:19)
System.err:     at android.app.Activity.performCreate(Activity.java:7802)
System.err:     at android.app.Activity.performCreate(Activity.java:7791)
System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
System.err:     ... 11 more

The import in main.ts file looks like following:

import { platformNativeScriptDynamic } from "@nativescript/angular";

If I change it to:

import { platformNativeScriptDynamic } from "@nativescript/angular/platform";

everything works. As mentioned in this issue #1540 (actually in the solution mentioned in it), I guess it has something to do with importing reflect-metadata.

Do I need to also use more specific imports elsewhere to avoid any other issue (such as import { NativeScriptModule } from "@nativescript/angular/nativescript.module") or is it ok to do just import { Something } from "@nativescript/angular" everywhere else?

@NathanWalker
Copy link
Contributor

@armpogart is possible to share or invite collaborator on project? I’d be happy to submit a PR to help you clear?

@armpogart
Copy link
Author

@NathanWalker I have tried scoped packages on a blank project before migrating my live application, so here is a zipped blank test project. Just run:

tns install
tns run android

and you will see the crash. It works only if you change the import in main.ts to:

import { platformNativeScriptDynamic } from "@nativescript/angular/platform";

TestApp.zip

@NathanWalker
Copy link
Contributor

NathanWalker commented Jun 26, 2020

@armpogart you have to use the --env.aot flag as mentioned here: https://github.com/NativeScript/nativescript-angular/wiki/Updating-and-developing-for-@nativescript-angular-v9-with-Ivy-or-without

tns run android --env.aot

With Angular 10, we will bake that flag into the webpack.config but for now that flag is mandatory (albeit optional since you can still disable ivy if needed)

@armpogart
Copy link
Author

armpogart commented Jun 26, 2020

@NathanWalker I see, but your guide and AOT flag is for Angular 9, I use Angular 8.2 in that project. Is it also mandatory to use AOT build for Angular 8?

P.S. I still use AOT for release build only.

@NathanWalker
Copy link
Contributor

@armpogart ah i see you mentioned Angular 8 -- I would try to keep AoT on all the time - it's likely it could also lead to an error like you mentioned there when omitting env.aot.

@armpogart
Copy link
Author

@NathanWalker I will try your suggestion a little bit later and report back here. But is it ok that everything is working fine without env.aot if I don't use scoped packages, I mean if I just blank angular template (which is currently using angular version 8) and run it, everything works. As soon as I change to scoped packages I start getting the error. Maybe it's just something wrong in scoped packages? Or is also connected with aot?

P.S. I wasn't simply using env.aot all the time (during development) as I guess the flag will increase compilation time by doing ahead of time compilation which will increase app performance obviously, but during development compilation time is more critical, especially for the larger projects (not just blank template).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants