joachim_b
joachim_b

Reputation: 213

angular 12 webworker 404

I have updated my project from Angular 11 to Angular 12 and got everything working except of my webworkers. When I do a build, the worker.ts files are not copied to the output directory and when loading in ng serve, I get a 404 for the worker files.

In angular.json under "build" I have this:

  "webWorkerTsConfig": "tsconfig.worker.json"

and my tsconfig.worker.json contains this:

 {
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/worker",
    "lib": [
      "es2018",
      "webworker"
    ],
    "types": []
  },
  "include": [
    "src/**/*.worker.ts"
  ]
}

I didn´t change anything here....how can i trace why it doesn´t include the worker.ts files?

Upvotes: 1

Views: 1794

Answers (2)

stephaneb
stephaneb

Reputation: 167

I got this message when I forgot to re-run yarn start to recompile my app

Upvotes: 0

joachim_b
joachim_b

Reputation: 213

Ok, I found the issue: I used to create the worker like so (and it worked for angular 11):

new Worker('/src/app/shared/workers/get-all-files.worker.ts',
        { name: 'getEntityMetricsLeg', type: 'module' })

After I changed to the below, everything worked again:

new Worker(new URL('/src/app/shared/workers/get-all-files.worker.ts', import.meta.url),
        { name: 'getEntityMetricsLeg', type: 'module' })

Upvotes: 6

Related Questions