-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty Worker returned after hot-reloading #24
Comments
Strange! What version of Webpack? |
@developit v3.10 I'm using a very basic setup. |
I'm also experiencing this all of a sudden. v1.0.2 seems to have broken webpack 3. I've set v1.0.1 in my package.json for now. |
Ah interesting 1.0.1 works - I'll see if there's anything fishy in the diff. |
Looks like #26 is the culprit: |
@developit I think that is might be related to #32 UPD: I've tried v1.1 (before 71b1df8) and still facing the issue It seems that issue is related to HMR. I'll try to describe my enviroment so that you could suggest where we may start bug detection. I'm using vue-cli@2 "webpack" template (it's Vue version of create-react-app, but already ejected). Used workerize loader like that:
No changes to default webpack config were made
{
"presets": [
["env", {
"modules": false,
"useBuiltIns": true
}],
"stage-2"
],
"plugins": ["transform-vue-jsx", "transform-runtime"],
} In some time after few HMR updates MyWorker constructor always returns: Hope that can help to identify issue. In near future I'll try to create a repository that reproduces the issue. |
Based on @developit suggestion to play around with In the file that proxies the worker import MyWorker from './MyWorker.worker';
let cache;
if (module.hot) {
module.hot.accept(['./MyWorker.worker'], () => {
if (cache) {
// eslint-disable-next-line global-require
const MyWorkerLatest = require('./MyWorker.worker');
cache = new MyWorkerLatest();
}
});
}
export default () => {
if (!cache) {
cache = new MyWorker();
}
return cache;
}; |
I forgot to mention a detail: once the "bad" worker is returned for first time the environment is spoiled forever. Even after reloading page the worker is "bad". Only |
I'm also experiencing this issue. Even if I disable HMR in my project (hot: false for the dev server, remove the babel plugin and the HotModuleReplacementPlugin), the methods are still undefined after any recompile. Using workerize-loader requires me to restart the build after every change which is not sustainable. And since I am using Webpack 4 I cannot downgrade to 1.0.1. |
Nevermind, turning off cacheDirectory worked for my simple test worker, but as soon as I started implementing what I really want to do I'm back to the same old behavior where no methods are present on the worker object after any recompile. The investigation continues... |
Now I found the root fo the problem: the |
…e, instead of using the compilation object. Fixes developit#24 where worker methods are undefined after a recompile.
I have the follwing situation: const worker = require('workerize-loader!./worker')
Is it this bug? Is it going to be fixed? |
I tried this (edited the index.js file in the dist/ folder locally) and it works. I haven't had to change the code in my worker to see if there are any side effects but the annoying issue is gone for now. I don't have to re-run my serve script on every change. Thanks. |
I'm having the same issue (no babel) when using together with ts-loader: test.worker.ts
the |
Any updates on a solution for this? I am having this issue as well. It seems to only happen when I set webpack to production configuration. |
@shayke Maybe it is not your |
For some reason, no methods are being exposed.
After I run webpack, and then make changes to a file
import
ed intoWorker.js
, the Worker file returns an empty Worker with no methods. I think hot-reloading chunks doesn't play well with this loader. Restarting Yarn and refreshing the browser seems to fix the issue.Worker.js
App.js
The text was updated successfully, but these errors were encountered: