start-javascript / ngx-web-worker

Web worker for angular.
33 stars 7 forks source link

Uncaught ReferenceError: _helper_class__WEBPACK_IMPORTED_MODULE_0__ is not defined #4

Open jacopolanzoni-pq opened 5 years ago

jacopolanzoni-pq commented 5 years ago

I am working on an Angular 6 app, and I am trying to use a web worker Worker (via ngx-web-worker) to perform some complex and CPU-expensive operations. I have the following service:

import { MY_SCRIPT } from './my-script.script';
import { WebWorkerService } from 'ngx-web-worker';

@Injectable({
  providedIn: 'root',
})
export class MyService {

  constructor(private webworkerService: WebWorkerService) {

    this.webworkerService.run(MY_SCRIPT).then((data) => {
      console.log(data);
    }, (error) => {
      console.error(error);
    });

  }

}

where my-script.script.ts contains the following:

import { HelperClass } from './helper.class';

export const MY_SCRIPT = () => {

  const helperClass: HelperClass = new HelperClass();
  helperClass.doExpensiveComputation();

};

and helper.class.ts contains the following:

export class HelperClass {

  doExpensiveComputation() {
    // do some complex and expensive computation
  }

}

The class HelperClass is not imported in any Angular module. The app builds fine, but at runtime I get an error with the following message:

Uncaught ReferenceError: _helper_class__WEBPACK_IMPORTED_MODULE_0__ is not defined

How can I give webpack the information it needs?

https://stackoverflow.com/questions/54519923/how-can-webpack-serve-files-to-a-web-worker-in-an-angular-6-app