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

[how-to] use workers with webpack #229

Closed
echap opened this issue Jul 19, 2017 · 14 comments
Closed

[how-to] use workers with webpack #229

echap opened this issue Jul 19, 2017 · 14 comments

Comments

@echap
Copy link

echap commented Jul 19, 2017

I am trying to use a webworker within my project for background computation purposes.

here are my versions :

All NativeScript components versions information
┌──────────────────┬─────────────────┬────────────────┬─────────────┐
│ Component        │ Current version │ Latest version │ Information │
│ nativescript     │ 3.1.2           │ 3.1.2          │ Up to date  │
│ tns-core-modules │ 3.1.0           │ 3.1.0          │ Up to date  │
│ tns-android      │ 3.1.1           │ 3.1.1          │ Up to date  │
│ tns-ios          │ 3.1.0           │ 3.1.0          │ Up to date  │

When I was using {N} 2.5.5, I had a system built like that :

  • My application was using a webpack-compiler wrapper made by triniwiz
  • I made a variable, globals.isAoT that I used to set in mymain.ts and main.aot.ts and checked in my worker instanciation
  • At instanciation, it looked like that :
try {
            if(this.isAoT) {
                let WW = require("worker-loader!./voronoi.worker.js");
                this._mainWorker = new WW;
            } else {
                this._mainWorker =  new Worker("./voronoi.worker.js");
            }
        } catch(error) {
            console.log("VoronoiWorkerService::instanciateMainWorker() : ", error);
        }

And is was working well.

With {N} 3.1.1, I dropped usage of the globals variable, but all the rest is still the same but this is not working anymore.

The issue is :

Exception in thread "main" java.io.IOException: File already exists. This may lead to undesired behavior.
Please change the name of one of the extended classes.
File:/home/eric/my-project/platforms/android/src/main/java/com/tns/FragmentClass.java Class: com.tns.FragmentClass
        at org.nativescript.staticbindinggenerator.Generator.writeBindings(Generator.java:68)
        at org.nativescript.staticbindinggenerator.Main.main(Main.java:15)
:asbg:generateBindings FAILED

My question then is, how am I supposed to use my webworker with {N} 3.1.1 webpacked ? Thanks a lot !

@danielgek
Copy link

@echap the problem is already reported, take a look at these issues: #176 and #778

@echap
Copy link
Author

echap commented Jul 20, 2017

@danielgek Yes I've been through those posts, but it's unclear if it is a bug or something else, and it seems to me untrackable for the next people who will try to find out how to use workers with webpack.

As of today, we can't send in production new version of our application for this very single reason :(

@echap
Copy link
Author

echap commented Jul 20, 2017

I'd be glad if I could have any kind of workaround 🆘

@danielgek
Copy link

Currently i don't have any workaround for this and i think the team hasn't too(@Pip3r4o)

i actually have shipped the app i'm working on w/o AOT :(

@echap
Copy link
Author

echap commented Jul 21, 2017

@danielgek sadely that's impossible for us to do so. I'll wait untill next week for our next release, hopping it will get back to work 🙏

@hypery2k
Copy link

I've read to all the issues and found this commit. If I know use "@ngtools/webpack": "1.6.0-beta.1" a got the following error:

ERROR in ../~/nativescript-dev-webpack/tns-aot-loader.js!../~/@ngtools/webpack/src!./workers/cleanup.db.worker.ts
    Module build failed: Error: @ngtools/webpack is being used as a loader but no `tsConfigPath` option nor AotPlugin was detected. You must provide at least one of these.
        at Object.ngcLoader (.../node_modules/@ngtools/webpack/src/loader.js:429:1

Seems related to these issues, here and here.

@danielgek
Copy link

@hypery2k is that for issue #139 ? xD

@echap
Copy link
Author

echap commented Jul 24, 2017

Any update on this ?

@echap
Copy link
Author

echap commented Aug 4, 2017

Still nothing on this ?

@petekanev
Copy link

@echap we are committed to addressing the problem in the 3.2 release. We'll let you know when it's fixed. There are no workarounds currently, except to avoid importing tns-core-modules, or plugins depending on these inside your worker script.

@triniwiz
Copy link
Member

@Pip3r4o a work around for me can be found here https://github.com/TeamMaestro/nativescript-pspdfkit/blob/master/src/ios/pspdfkit.ts#L50-L56 after installing the modifed worker-loader in my repo

@echap
Copy link
Author

echap commented Aug 13, 2017

@triniwiz Is this working only for ios ? (since your chances are here ?), Haven't tried it yet !

@triniwiz
Copy link
Member

@echap it works for both platform

@sis0k0
Copy link
Contributor

sis0k0 commented Jan 10, 2018

You can now use the nativescript worker-loader. You can find more info and demo apps in the repo of the plugin: https://github.com/nativescript/worker-loader. The plugin is also included in the default webpack configuration that the nativescript-dev-webpack plugin adds.

@sis0k0 sis0k0 closed this as completed Jan 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants