Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

webpack --bundle switch causing : Failed to find module #446

Closed
RoyiNamir opened this issue Feb 26, 2018 · 3 comments
Closed

webpack --bundle switch causing : Failed to find module #446

RoyiNamir opened this issue Feb 26, 2018 · 3 comments

Comments

@RoyiNamir
Copy link

RoyiNamir commented Feb 26, 2018

I'm using the latest 3.4.1 version with Android. It seems that adding --bundle is causing some issues.

When AndroidManifest.xml has : android:name="com.tns.NativeScriptActivity" , then everything is working fine.

It runs OK even with tns run android --bundle

Now I set android:name="org.nativescript.fingerprintplugin.AppCompatActivity" without --bundle ,and it runs OK.

However , When I use --bundle and : [ android:name="org.nativescript.fingerprintplugin.AppCompatActivity"] -
(https://github.com/EddyVerbruggen/nativescript-fingerprint-auth#mandatory-change) instead , then I get an error :

Error: com.tns.NativeScriptException: Failed to find module: "./tns_modules/nativescript-fingerprint-auth/appcompat-activity.js", relative to: app//
System.err:     com.tns.Module.resolvePathHelper(Module.java:146)
System.err:     com.tns.Module.resolvePath(Module.java:55)
System.err:     com.tns.Runtime.runModule(Native Method)
System.err:     com.tns.Runtime.runModule(Runtime.java:530)
System.err:     com.tns.Runtime.createJSInstance(Runtime.java:624)
System.err:     com.tns.Runtime.initInstance(Runtime.java:606)
System.err:     org.nativescript.fingerprintplugin.AppCompatActivity.<init>(AppCompatActivity.java:7)
System.err:     java.lang.Class.newInstance(Native Method)
System.err:     android.app.Instrumentation.newActivity(Instrumentation.java:1078)
System.err:     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2538)
System.err:     android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
System.err:     android.app.ActivityThread.-wrap12(ActivityThread.java)
System.err:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
System.err:     android.os.Handler.dispatchMessage(Handler.java:102)
System.err:     android.os.Looper.loop(Looper.java:154)
System.err:     android.app.ActivityThread.main(ActivityThread.java:6077)
System.err:     java.lang.reflect.Method.invoke(Native Method)
System.err:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
System.err:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
System.err: File: "<unknown>, line: 1, column: 265

Full log

Of Course i've tried platform remove/add

And this is a sample empty project which shows the problem
``

image

@NickIliev
Copy link
Contributor

NickIliev commented Feb 26, 2018

@RoyiNamir the plugin used is extending the Android activity in its own plugin folder.
However, to bundle an application with an extended activity we need to pass the activity file to our webpack.config.js. as demonstrated here

Instead of passing a path to node_modules folder I have resolved this issue by recreating the extended activity class in my app folder and adding it to the entry as MainActivity in webpack-config file.

For example:

import { setActivityCallbacks, AndroidActivityCallbacks } from "tns-core-modules/ui/frame";

@JavaProxy("org.nativescript.fingerprintplugin.AppCompatActivity")
class Activity extends android.support.v7.app.AppCompatActivity {
  private _callbacks: AndroidActivityCallbacks;

  protected onCreate(savedInstanceState: android.os.Bundle): void {
    if (!this._callbacks) {
      setActivityCallbacks(this);
    }

    this._callbacks.onCreate(this, savedInstanceState, super.onCreate);
  }

  protected onSaveInstanceState(outState: android.os.Bundle): void {
    this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState);
  }

  protected onStart(): void {
    this._callbacks.onStart(this, super.onStart);
  }

  protected onStop(): void {
    this._callbacks.onStop(this, super.onStop);
  }

  protected onDestroy(): void {
    this._callbacks.onDestroy(this, super.onDestroy);
  }

  public onBackPressed(): void {
    this._callbacks.onBackPressed(this, super.onBackPressed);
  }

  public onRequestPermissionsResult(requestCode: number, permissions: Array<String>, grantResults: Array<number>): void {
    this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined);
  }

  protected onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void {
    this._callbacks.onActivityResult(this, requestCode, resultCode, data, super.onActivityResult);
  }
}
  • run tsc (or tns build) to trigger the transpliation to JavaScript
  • add the extended activity as MainActivity in webpack.config.js
entry: {
    bundle: aot ? "./main.aot.ts" : "./main.ts",
    vendor: "./vendor",
    MainActivity: "./appcompat-activity"
},
  • And finally, bundle with WebPack
tns run android --bundle

@NickIliev
Copy link
Contributor

NickIliev commented Feb 26, 2018

@RoyiNamir if you are using --env.snapshot you should also add the android specific file to vendor-platform.android.ts as done here

Related documentation section here.

@alexma01
Copy link

alexma01 commented May 2, 2018

Hi @RoyiNamir ,

if i extend com.google.firebase.messaging.FirebaseMessagingService how do I say it in the webpack.config.js?

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

No branches or pull requests

3 participants