-
-
Notifications
You must be signed in to change notification settings - Fork 136
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
Static binding generator fails when using Webpack + Workers #778
Comments
Starting off I'd like to point something out - that behavior IS expected. The build-time exception is often a sign that something isn't quite right with the files - you have dupes, or you extend the same class, with the same name, meaning if the build was uninterrupted - only one of the two extended classes will pass, which may result in unexpected behavior/bugs runtime. I think we can make it so the sbg will spit out a warning message when two of the same classes have the same content, and not throw, while still throwing an exception with that particular error message if contents of the two files differs. |
@Pip3r4o i saw your branch about this issue, do you have a build i can test/use ? |
@danielgek you can fetch the branch, and build the .jar locally, then simply replace it in However these changes will not fix or work around the problem that @sis0k0 has described with webpacked workers. While the two files whose contents are being compared may look the same, there is a very important bit (JavaScriptImplementation annotation) that will fail the check. |
@Pip3r4o i was already doing that xD, but yeah i got the same error, thanks for the help !! |
I'm hitting this same issue when developing plugins that have In case of plugins the CLI/Runtime should detect that a new version of the plugin is used and should automatically remove the old java classes that have been generated by this plugin so the new ones can be generated successfully. Or it should just override the existing classes with the new ones. |
@PeterStaev I recently pushed a change to the sbg logic to make it less aggressive during a build. That is achieved by always invalidating the list of to-be-generated classes. |
Thanks @Pip3r4o ! I've just tried the |
I was having an issue with a duplicated DropDownAdapter class from nativescript-drop-down and @next solved it. |
I am still experiencing this issue when running
Did I understand wrong that this was supposed to be fixed in this version? |
Having duplicate classes with the same name will fail your build, and that is expectrd, yes. Read the error carefully and see where the conflicts are. |
@Pip3r4o thanks for the reply. As far as I understand, I encounter this issue due to a web worker that I am using in my plugin as is explained in this issue. Shouldn't web workers be supported out of the box? I see that @sis0k0 explains that "you don't really need to import globals in your worker" so I tried not to include the globals in the worker, but even then I am getting the same error:
|
Hi, I believe I am having the same problem as @sis0k0 , trying to webpack an {N} app with a web worker:
I waited a few weeks before migrating to {N} V3, but now, it is becoming more and more pressing that I keep my app up to date :) So is there a workaround for workers, or is there a release where this prob is fixed ? Thanks |
@quentinor we have not put any specific effort towards resolving this particular issue. We are still deliberating how to best handle the case with webpack, since it essentially pours the scripts you already use in the main bundle into the worker script bundle. The static binding generator does not, at this point, differentiate between a regular script, and one that will be used on a worker thread. For the time being, avoid importing the tns-core-modules into a worker script, when webpacking. That should be sufficient to let the android build complete. |
Hello Pip3r4o. You said:" For the time being, avoid importing the tns-core-modules into a worker script, when webpacking. That should be sufficient to let the android build complete." How do you do that? |
@leocrawf don't import |
I updated my project to 3.2.0. I'm still experiencing issues as described above when using |
@bfv for me it is working fine. Make sure you are using |
I am using nativescript-dev-webpack v0.8.0. Strange. |
@bfv yeah I had some issues as well, until I just created a new project and then copied my app dir and relevant files to the new project and did the installation of |
@bfv @abhayastudios |
Is this the official and permanent solution for worker threads and web-pack - or is this a temporary fix. btw I commented out my global imports and I was still getting the FragmentClass refined error. |
@erjdriver https://github.com/nativescript/worker-loader is the official way of getting workers working with AOT/Webpack |
same problem, how to solve it ? |
@Nurgunkalol please have a look at the README at https://github.com/nativescript/worker-loader explaining how to configure the worker loader for webpack. |
I followed the instructions - developing in typescript. I installed nativescript-worker-loader. The webpack.config.js file was auto generated Then I tried to include the worker file as: import * as WorkerScript from "nativescript-worker-loader!./worker-script"; with worker-script replaced with my filename. I'm getting a module not found error in vscode. but if I ignore it and build/run it, I get the same redefinition FragmentClass error. This is in android with 3.2 |
@erjdriver I'm pretty sure you need to feed a
|
@abhayastudios the README page says support for typescript files. |
@erjdriver TypeScript files are transpiled down to JavaScript, so you should have javascripts at runtime. |
I'm using the syntax in the README file for ts worker files import * as WorkerScript from "nativescript-worker-loader!./worker-script"; I understand TS compiles down to JS. But in the app folder there's no .js files - even for my other files. I assume that's something webpack is doing - storing it somewhere else. Issue #1 is that above import statement results in module-not-found error. Even though I've got the correct ts file in the app folder. Issue #2 is at startup time, I get the FragmentClass redefinition error that the OP wrote about. |
Here's the error that gets displayed when i try to webpack on the android Note the error "not cacheable" `[224] ../node_modules/nativescript-worker-loader!./worker-check-version.ts 119 bytes {0} [not cacheable] [built] ERROR in [at-loader] ./app/utils.ts:19:37 When I try to include the file from /app/utils.ts file -I get the cannot-find-module error |
@erjdriver as far as I know you need to explicitly reference the Regarding the FragmentClass exception: are you sure you are using |
@abhayastudios thank you for your suggestions.
|
You can run |
@erjdriver since your worker is done in TypeScript, did you follow the README steps strictly? Did you make a typings file? -> https://github.com/nativescript/worker-loader#integrating-with-typescript |
ok making some progress. I added the typings folder in the root and am not getting the module-not-found error any more. The build succeeds. But when the app tries to run in the emulator. I removed and added the android platform before the build. `finished with reading lines with js files FAILURE: Build failed with an exception.` |
This issue is still not fixed - not sure why it was closed. Still getting the duplicate FragmentClass error. I've commented out all the Worker references and still getting the error. |
@erjdriver please provide a minimalistic sample repository to help us debug the problem, as I am unable to reproduce it on my end. |
@erjdriver did you try |
Seems there is some problem with |
@PeterStaev I am not sure it is a problem with the @next of the android runtime. I tested master branch of your plugin's demo (tns build android) with the latest versions of angular and the nativescript-angular plugin. The project built fine without exceptions. |
@Pip3r4o seems you are correct. It could have been something specific to the specific version that was used in the PR. With the resubmited PR with |
@erjdriver I created a minimalistic sample of loading a worker in typescript, following the nativescript-worker-loader README. You can find the sample in the |
@Pip3r4o - thanks for getting back to me and taking the time to create the test project. I solved the problem. The problem was that in my bundle-config.ts file, I had
I was getting the multiple definition of FragmentClass. If I comment out the second line - then it works. Weird because I got those two lines from some sample projects on github. Hopefully this will help someone else... |
Example case:
Setup - project with web worker file where the worker imports 'globals'.
If you webpack the project, a bundle named
[hash].worker.js
will be generated and it will contain the wholetns-core-modules
package.Since
tns-core-modules
is also contained in the vendor chunk, the static binding generator will fail:The text was updated successfully, but these errors were encountered: