2

I created my first plugin: https://www.npmjs.com/package/nativescript-ftp-client And it is working when in development mode (using seed project), But when I package it app says it cannot find a ftp-worker-android.js file which is included Problem is that I am using new Worker('./ftp-worker-android.js'); and it gives an error. If I try to include it with import at the beginning of a file it get's included so I know that it is in the package but worker can't seem to load, it gives following error: JS: [Error: com.tns.NativeScriptException: Failed to find module: "./ftp-worker-android.js", relative to: app//

dfilkovi
  • 3,051
  • 7
  • 39
  • 51

1 Answers1

2

You have to conditionally use nativescript-worker-loader plugin to initialise worker on webpack builds.

    var worker;
    if (global.TNS_WEBPACK) {
        var GrayscaleWorker = require('nativescript-worker-loader!./ftp-worker-android.js');
        worker = new GrayscaleWorker();
    } else {
        worker = new Worker('./ftp-worker-android.js');
    }
Manoj
  • 21,753
  • 3
  • 20
  • 41
  • As I am developing plugin in plain JS, is there a way to do it inside a plugin so that users using this plugin don't need to change webpack config? As I see on the plugin installation guide you need to include that plugin in webpack.config.js – dfilkovi Mar 03 '19 at 11:28
  • This has nothing to do with webpack config. The code above is just a replacement for your require statement within plug-in – Manoj Mar 03 '19 at 12:28