question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular production builds breaks the web worker

See original GitHub issue

(Re-describing #13 in a reproducible manner)

Repro repo with code and clear description of the problem: https://github.com/monocl-oskar/observable-webworker-problem

When web workers created with observable-webworker gets run through Angular’s production build mangling, they get destroyed.

For instance, this:

import { DoWork, ObservableWorker } from 'observable-webworker';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@ObservableWorker()
class HelloWorker implements DoWork<string, string> {
  public work(input$: Observable<string>): Observable<string> {
    return input$.pipe(
      map(message => {
        return 'Hello from observable webworker';
      }),
    );
  }
}

Gets mangled into this (ran through a beautifier):

! function(e) {
    var t = {};

    function r(n) {
        if (t[n]) return t[n].exports;
        var o = t[n] = {
            i: n,
            l: !1,
            exports: {}
        };
        return e[n].call(o.exports, o, o.exports, r), o.l = !0, o.exports
    }
    r.m = e, r.c = t, r.d = function(e, t, n) {
        r.o(e, t) || Object.defineProperty(e, t, {
            enumerable: !0,
            get: n
        })
    }, r.r = function(e) {
        "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, {
            value: "Module"
        }), Object.defineProperty(e, "__esModule", {
            value: !0
        })
    }, r.t = function(e, t) {
        if (1 & t && (e = r(e)), 8 & t) return e;
        if (4 & t && "object" == typeof e && e && e.__esModule) return e;
        var n = Object.create(null);
        if (r.r(n), Object.defineProperty(n, "default", {
                enumerable: !0,
                value: e
            }), 2 & t && "string" != typeof e)
            for (var o in e) r.d(n, o, (function(t) {
                return e[t]
            }).bind(null, o));
        return n
    }, r.n = function(e) {
        var t = e && e.__esModule ? function() {
            return e.default
        } : function() {
            return e
        };
        return r.d(t, "a", t), t
    }, r.o = function(e, t) {
        return Object.prototype.hasOwnProperty.call(e, t)
    }, r.p = "", r(r.s = "zAnl")
}({
    zAnl: function(e, t, r) {
        "use strict";
        r.r(t), Error, "function" == typeof Symbol && Symbol
    }
});

No trace of 'Hello from observable webworker' or even addEventListener for the web worker.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
zakhenrycommented, Aug 1, 2019

🎉 This issue has been resolved in version 3.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

1reaction
zakhenrycommented, Aug 1, 2019

Hey @monocl-oskar thanks for the clear repro, I will dig into this likely on the weekend. It’s an interesting problem as I’m not getting the same result in the demo for this repo which is also an angular prod build.

Read more comments on GitHub >

github_iconTop Results From Across the Web

web worker with deploy-url CDN cause SecurityError #14901
Angular 8 support build web worker command, but when the app deploys to CDN with --deploy-url , the web worker ts will also...
Read more >
Service worker in production - Angular
Whenever a new build of the application is deployed, the service worker treats ... This way, broken unhashed resources do not remain in...
Read more >
Using imported function is crashing web worker - Stack Overflow
I have an electron app running angular 8+. I'm calling a function ... src/app/dead-link-checker.worker.ts) Module build failed (from .
Read more >
Running Web Worker in Angular 6 Application - Medium
Configure Angular builder to build our web worker code. Create webpack.config.worker.js file under project root directory. This configuration ...
Read more >
Using Web Workers with Angular 6 App generated ... - LinkedIn
Based on standard conventions, familiar design patterns, strongly typed code, built-in data streaming, modular CLI and server-side rendering, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found