Closed romulowspp closed 7 years ago
@Ablankzin,
Can you share some details about your project? How many worker scripts do you have? Are you providing them to the worker loader (var MyWorker = require("worker-loader!./file.js")
)? Thanks!
Please, note that the plugin is still under development.
@sis0k0,
hello. Let me show a piece of my code:
export class ConversationComponent implements OnDestroy, OnInit {
worker: Worker = new Worker("worker-loader!./../../services/worker/conversation.worker");
i'm using nativescript with angular. When i run without webpack it's works.
Looking into code, i see that:
compilation.workerChunks
Is undefined. I don't know why.
;)
It must be that the loader cannot find the conversation.worker
. Can you transpile that file manually to js and then change the require to new Worker("worker-loader!./../../services/worker/conversation.worker.js");
?
I transpile and use .js and same error happen.
Update.
Now with your update i receive this error in webpack process.
ERROR in ../node_modules/nativescript-dev-webpack/tns-aot-loader.js!../node_modules/@ngtools/webpack/src!./modules/main/services/worker/conversation.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 (/mobile/node_modules/@ngtools/webpack/src/loader.js:434:19)
I change the code to:
import * as MyWorker from "worker-loader!./../../services/worker/conversation.worker";
worker: Worker = new MyWorker();
:)
Hey @Ablankzin,
I will write later today with the solution and will add a demo application showing the approach. Thanks for your patience! :)
@Ablankzin,
The problem is caused by the @ngtools/webpack loader which is used to transpile the TS files to JS.
We need to provide a typescript configuration to the @ngtools/webpack loader, because the one it uses by default - the one from the AotPlugin - is no longer available.
When the worker script is ran through the loader, the AoT plugin instance is no longer part of the compilation object. In short, we need to provide the same path for a tsconfig.json
to the loader, that we are using for the plugin. Check out the modified webpack.config.js
:
Options for Angular's webpack plugin and loader:
https://github.com/NativeScript/worker-loader/blob/165ba7038dd455bd0ddd466eeb6d1c3ed4789a42/demo-angular/webpack.config.js#L13
TypeScript loaders: https://github.com/NativeScript/worker-loader/blob/165ba7038dd455bd0ddd466eeb6d1c3ed4789a42/demo-angular/webpack.config.js#L135-L144
I've made a simple demo app in the repo, that you can refer to if you have any problems. Of course, don't hesitate to ask if something is unclear :)
I've tested in my project and works! Thank you!
But only work with next release of runtime. I will wait next release and watch this awesome project.
Yup, it will be part of the 3.2 release of the Android runtime which is coming in a few days :)
I just stumbled upon this thread in search of a solution for the same "Error: @ngtools/webpack is being used as a loader but no tsConfigPath
option nor AotPlugin was detected." using the worker-loader plugin. Passing the tsConfigPath to the loader as you suggested worked!
Thanks so much!
var MyWorker = require("worker-loader!./file.js")
@sis0k0 where the file.js should place? ini node_modul/nativescript-worker-loader ? or in src ?
I try to use this plugin and with webpack i get this error:
My package.json:
Can you help me? :dancing_men: