NativeScript / worker-loader

36 stars 20 forks source link

The AngularCompilerPlugin was not found. #23

Closed valera1401 closed 5 years ago

valera1401 commented 5 years ago

Error occurs if some ts class is imported inside typescript.worker.ts.

It can be reproduced easily in the demo app. Just create some ts class and import it in typescript.worker.ts.

jerbob92 commented 5 years ago

I also have this issue. I tried to inject services from the Angular app so we can use the same classes/logic in the workers, but this doesn't really seem to be possible sadly. The worker support in NativeScript doesn't really seem to be that much used. How do people let their app perform?

pacome2017 commented 5 years ago

I have the same error, I only import 'globals' in my workers. I'm trying to add webpack bundling, it worked ok without.

JohnnyClutch commented 5 years ago

I have the same problem with webpack and a worker. Using worker-loader as so:

const SEARCH_WORKER = require('worker-loader!../../../../workers/search');

Error from webpack dev server output:

ERROR in ./src/workers/search.ts (./node_modules/@ngtools/webpack/src!./src/workers/search.ts)
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: The AngularCompilerPlugin was not found. The @ngtools/webpack loader requires the plugin.
    at Object.ngcLoader (/Users/gbullock/projects/gadmin-ui/node_modules/@ngtools/webpack/src/loader.js:27:15)
dpavez14 commented 5 years ago

Take a look to this answer: https://stackoverflow.com/a/54546214/4982126

darkyelox commented 5 years ago

I have this problem and i can't import any class from my Angular project using Typescript worker making this plugin almost useless and worst being the only way for threading in nativescript. You must fix this ASAP because is affecting the perception of NativeScript.

Pala2812 commented 5 years ago

Also facing this issue. Unfortunately being able to process some long running tasks is a requirement for me so... This could be the reason to drop NS. Has anyone found a workaround ?

NickIliev commented 5 years ago

@Pala2812 have you tried the solution suggested by @dpavez14 here

Pala2812 commented 5 years ago

Need to try it tonight, if we pass an object to worker would we be able to call the functions. For example:

const backendLogic = new backendLogic () worker.postmessage({backend: backendLogic})

And in worker context.onmessage = msg => { msg.data.backend.init(); const data =msg.data.backend.getData(); context.postmessage(data) }

Pala2812 commented 5 years ago

i got it mostly working using the js worker - but now i've run into a problem. when calling native api like com.microsoft.azure.storage.table.TableOperationType.delete it does not work as delete is a reserved js word. Any idea how to solve this ?

edusperoni commented 5 years ago

@NickIliev I decided to revisit this issue (past discussion here: https://github.com/NativeScript/worker-loader/issues/20). I finally managed to fix this issue in my project using this as reference: https://github.com/GoogleChromeLabs/worker-plugin/issues/13

Using the proposed solution generated another error inside nativescript-dev-webpack, which I believe comes from GenerateBundleStarterPlugin, so I modified the code to do the following:

const compilerOptions = this._compiler.options || {};
    console.log(compilerOptions.plugins);
    const workerCompiler = this._compilation.createChildCompiler("worker", outputOptions, [compilerOptions.plugins[6]]);

compilerOptions.plugins[6] was the AngularCompilerPlugin, in my case. (this is just a hack and proof of concept)

After this I was able to successfully import ts files and use the worker as I desired. So it seems the worker is not using the correct plugins.

I suggest we migrate from using worker-loader as a base implementation, to worker-plugin, which has proper support for plugins (including named plugins and etc).

NidheeshMv commented 2 years ago

Hello @edusperoni ,

I am getting the below error when i doing ns run ios.

Fatal JavaScript exception - application has been terminated. NativeScript encountered a fatal error: Uncaught Error: Module build failed (from ./node_modules/@ngtools/webpack/src/index.js): Error: The Angular Webpack loader requires the AngularWebpackPlugin. at Object.angularWebpackLoader (/app/node_modules/@ngtools/webpack/src/ivy/loader.js:44:18) at ./src/polyfills.ts(file:///app/bundle.js:17:7) at webpack_require(file: src/webpack:/MobileCore-app/webpack/bootstrap:24:0) at webpack_exec(file:///app/bundle.js:27:39) at (file:///app/bundle.js:28:28) at (file:///app/bundle.js:33:3) at require(:1:137) (CoreFoundation) Terminating app due to uncaught exception 'NativeScript encountered a fatal error: Uncaught Error: Module build failed (from ./node_modules/@ngtools/webpack/src/index.js): Error: The Angular Webpack loader requires the AngularWebpackPlugin. at Object.angularWebpackLoader (/app/node_modules/@ngtools/webpack/src/ivy/loader.js:44:18) at ./src/polyfills.ts(file:///app/bundle.js:17:7) at webpack_require(file: src/webpack:/MobileCore-app/webpack/bootstrap:24:0) at webpack_exec(file:///app/bundle.js:27:39) at (file:///app/bundle.js:28:28) at (file:///app/bundle.js:33:3) at require(:1:137) ', reason: '(null)' First throw call stack:

NS CLI - 8.1.5 Angular CLI - 12.1.4

Please help me to resolve this

Thanks