NativeScript / worker-loader

36 stars 20 forks source link

Worker 0.10 works, 0.11 appears to crash/exit webpack #58

Closed NathanaelA closed 4 years ago

NathanaelA commented 4 years ago

I have just spent many hours tracing this issue down to the worker-loader; basically webpack starts bundling, gets to a certain spot crashes (or exits) with NO error and NO output, TNS thinks everything is fine and continues on and then fails on the runSBG. Unfortunately no where along this route does anything point to what the issue is, no logs, --log trace doesn't help, etc. Through a lot of tracing and modifying the code was I able to finally pinpoint that webpack is exiting/crashing.

This is a interesting corner case; Basically App loads NS-SQLite; NS-SQLite loads commercial, Commecrial loads webworker, which loads NS-SQLite. If you follow, at the point we are in the webworker, and we load NS-Sqlite, that of course requires commercial, and that requires webworker... So basically a require "loop". However as I said in #33, the webpack loader shouldn't allow a loop and should terminiate.

This chain now seems to confuse v0.11 where it has been working for quite a while properly as this has been the standard way this has worked since long before #33 was fixed. @rosen-vladimirov - It appears the PR's in 0.11 are yours; so you might have the best idea at what caused the change between v.10 and v0.11 that cause the loop short circuit to now be failing...

    // handle calls to itself to avoid an infinite loop
    if (requests.indexOf(request) === -1) {
        requests.push(request);
    } else {
        return callback(null, "");
    }

Moving this outside the promise seems to fix the issue...

image

Unless you can think of a reason not to do this, I think this restores the broken functionality; and a file that DOES not need to be parsed doesn't need to await any promises...

BTW: if you concur and you want me to do a PR just moving this code; let me know and I'll create a PR; but WebPack is NOT the code that I'm very knowledgeable about...

NathanaelA commented 4 years ago

Fixed in #59