Webpack 5 support
natew opened this issue ยท 14 comments
Haven't seen this reporter anywhere, tried out alpha 27 and with workerize-loader I get this:
TypeError: this.cache.get is not a function
at /Users/nw/projects/motion/orbit/node_modules/webpack/lib/Compilation.js:2186:18
at arrayEach (/Users/nw/projects/motion/orbit/node_modules/neo-async/async.js:2405:9)
at Object.each (/Users/nw/projects/motion/orbit/node_modules/neo-async/async.js:2846:9)
at /Users/nw/projects/motion/orbit/node_modules/webpack/lib/Compilation.js:2179:14
at symbolEach (/Users/nw/projects/motion/orbit/node_modules/neo-async/async.js:2444:9)
at Object.each (/Users/nw/projects/motion/orbit/node_modules/neo-async/async.js:2849:16)
at Compilation.createChunkAssets (/Users/nw/projects/motion/orbit/node_modules/webpack/lib/Compilation.js:2155:12)
at /Users/nw/projects/motion/orbit/node_modules/webpack/lib/Compilation.js:1479:10
at Hook.eval [as callAsync] (eval at create (/Users/nw/projects/motion/orbit/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/nw/projects/motion/orbit/node_modules/webpack/node_modules/tapable/lib/Hook.js:18:14)
at Compilation.seal (/Users/nw/projects/motion/orbit/node_modules/webpack/lib/Compilation.js:1377:27)
at /Users/nw/projects/motion/orbit/node_modules/webpack/lib/Compiler.js:768:19
at /Users/nw/projects/motion/orbit/node_modules/webpack/lib/Compilation.js:1301:4
at eval (eval at create (/Users/nw/projects/motion/orbit/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
at /Users/nw/projects/motion/orbit/node_modules/neo-async/async.js:2830:7
at Object.each (/Users/nw/projects/motion/orbit/node_modules/neo-async/async.js:2857:9)
Just curious, would "Webpack 5 support" mean migrating the project from Webpack 4 to 5?
@jbdoster it shouldn't require webpack 5, it's just a matter of checking for Webpack 5 when creating the child compiler's cache and using a Map
instead of a plain object.
I believe this can be solved by replacing this object with a Map
:
Line 92 in 68ea667
if (compilation.cache) {
- if (!compilation.cache[subCache]) compilation.cache[subCache] = {};
+ let cache;
+ if (compilation.cache instanceof Map) {
+ cache = compilation.cache.get(subCache);
+ if (!cache) {
+ cache = new Map();
+ compilation.cache.set(subCache, cache);
+ }
+ }
+ else if (!compilation.cache[subCache]) {
+ cache = compilation.cache[subCache] = {};
+ }
- compilation.cache = compilation.cache[subCache];
+ compilation.cache = cache;
}
If anyone wants to try that with Webpack 5 that'd be awesome.
Can you please add me
any progress here?
Yea I'm seeing issues as well.
32b9a0e681b8376cd0a7.worker.js:13141 Uncaught Error: Module parse failed: Cannot read property 'resource' of undefined
File was processed with these loaders:
* ./node_modules/workerize-loader/dist/rpc-worker-loader.js
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
TypeError: Cannot read property 'resource' of undefined
at /home/jessejorgenson/projects/daydash-ui/node_modules/workerize-loader/dist/index.js:97:44
at Hook.eval [as call] (eval at create (/home/jessejorgenson/projects/daydash-ui/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:5:16)
at Hook.CALL_DELEGATE [as _call] (/home/jessejorgenson/projects/daydash-ui/node_modules/webpack/node_modules/tapable/lib/Hook.js:14:14)
at JavascriptParser.blockPreWalkExportNamedDeclaration (/home/jessejorgenson/projects/daydash-ui/node_modules/webpack/lib/javascript/JavascriptParser.js:1882:35)
at JavascriptParser.blockPreWalkStatement (/home/jessejorgenson/projects/daydash-ui/node_modules/webpack/lib/javascript/JavascriptParser.js:1474:10)
at JavascriptParser.blockPreWalkStatements (/home/jessejorgenson/projects/daydash-ui/node_modules/webpack/lib/javascript/JavascriptParser.js:1395:9)
at JavascriptParser.parse (/home/jessejorgenson/projects/daydash-ui/node_modules/webpack/lib/javascript/JavascriptParser.js:3275:9)
at /home/jessejorgenson/projects/daydash-ui/node_modules/webpack/lib/NormalModule.js:844:26
at processResult (/home/jessejorgenson/projects/daydash-ui/node_modules/webpack/lib/NormalModule.js:625:11)
at /home/jessejorgenson/projects/daydash-ui/node_modules/webpack/lib/NormalModule.js:676:5
at http://localhost:8080/32b9a0e681b8376cd0a7.worker.js:13141:7
at http://localhost:8080/32b9a0e681b8376cd0a7.worker.js:13142:3
at http://localhost:8080/32b9a0e681b8376cd0a7.worker.js:13144:12
same issue as @jljorgenson18 ... will await the PR
util.js:586 Uncaught Error: Module parse failed: Cannot read property 'resource' of undefined
File was processed with these loaders:
* ../node_modules/workerize-loader/dist/rpc-worker-loader.js
* ../node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
TypeError: Cannot read property 'resource' of undefined
at /home/rob/src/web-spch-v2/node_modules/workerize-loader/src/index.js:100:37
at Hook.eval (eval at create (/home/rob/src/web-spch-v2/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:16)
at Hook.CALL_DELEGATE [as _call] (/home/rob/src/web-spch-v2/node_modules/tapable/lib/Hook.js:14:14)
at JavascriptParser.blockPreWalkExportNamedDeclaration (/home/rob/src/web-spch-v2/node_modules/webpack/lib/javascript/JavascriptParser.js:1884:35)
at JavascriptParser.blockPreWalkStatement (/home/rob/src/web-spch-v2/node_modules/webpack/lib/javascript/JavascriptParser.js:1476:10)
at JavascriptParser.blockPreWalkStatements (/home/rob/src/web-spch-v2/node_modules/webpack/lib/javascript/JavascriptParser.js:1397:9)
at JavascriptParser.parse (/home/rob/src/web-spch-v2/node_modules/webpack/lib/javascript/JavascriptParser.js:3284:9)
at doBuild.err (/home/rob/src/web-spch-v2/node_modules/webpack/lib/NormalModule.js:898:26)
at processResult (/home/rob/src/web-spch-v2/node_modules/webpack/lib/NormalModule.js:640:11)
at runLoaders (/home/rob/src/web-spch-v2/node_modules/webpack/lib/NormalModule.js:692:5)
at /home/rob/src/web-spch-v2/node_modules/loader-runner/lib/LoaderRunner.js:406:3
at iterateNormalLoaders (/home/rob/src/web-spch-v2/node_modules/loader-runner/lib/LoaderRunner.js:232:10)
at iterateNormalLoaders (/home/rob/src/web-spch-v2/node_modules/loader-runner/lib/LoaderRunner.js:239:10)
at /home/rob/src/web-spch-v2/node_modules/loader-runner/lib/LoaderRunner.js:254:3
at callback (/home/rob/src/web-spch-v2/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
at Object.rpcWorkerLoader (/home/rob/src/web-spch-v2/node_modules/workerize-loader/src/rpc-worker-loader.js:34:2)
at Object.../node_modules/workerize-loader/dist/rpc-worker-loader.js!../node_modules/babel-loader/lib/index.js??ruleSet[1].rules[0].use!./scripts/worker/create.js (http://localhost:8080/db5a895f58925c065a8b.worker.js:41044:7)
at __webpack_require__ (http://localhost:8080/db5a895f58925c065a8b.worker.js:41067:41)
at http://localhost:8080/db5a895f58925c065a8b.worker.js:41091:37
at http://localhost:8080/db5a895f58925c065a8b.worker.js:41093:12
This project seems to be death. Can anyone recommend a fork, which fix this issue and is still maintained?
@jens-duttke DIY to write your own worker along with a wrapper : https://codeburst.io/promises-for-the-web-worker-9311b7831733 has example that i followed so that the WP v 5 upgrade could complete and the dependency on workerize-loader removed. Now worker-loader is all that is req'd for webpack 5 and my project
@rowntreerob I use worker-loader
in another project, but I prefer the way how workerize-loader
wraps all this communication overhead away and makes it much easier to work with Workers.
Beside that, my project is using Gatsby and there is only one Gatsby plugin right now for "Workers":
https://www.gatsbyjs.com/plugins/gatsby-plugin-workerize-loader/
Unfortunately, this plugin is based on workerizer-loader
, which now doesn't work anymore, after the update to Gatsby 3, which relies on Webpack 5:
universse/gatsby-plugin-workerize-loader#6
There are 2 issues and ~3 PRs relating to this.
Some time to review and merge the PRs would be greatly appreciated ๐๐ป
Hi. Two major React frameworks, GatsbyJS and NextJS, have moved on to Webpack 5 with their latest major releases. Especially for Gatsby where there's no way to opt out of Webpack 5, this library has become a blocker for those who want to upgrade.
It would be much appreciated if you could spend some time making this library compatible with Webpack 5.
Facing the same thing out here, any solution yet?
Hi. After struggling to find an alternative which supports webpack 5, I ended up writing my own simple library which allows me to interact with workers just as I would with workerize-loader, but is bundler independent. Now with a couple modifications to the worker, and using worker-loader to load it, I can keep using it just as before and get typescript support as an added bonus!
I thought I'd share it as a gist in case it helps anyone. The code is tiny and single file so hopefully understanding and modifying it should be easy :D
https://gist.github.com/RedstoneWizard22/d07b326a438dd0449758c263cebd0e82