Comments (16)
Now I found the root fo the problem: the __workerizeExports
property is not persisted on the compilation object between recompiles, resulting in an empty list of methods after the first compile. I know next to nothing about Webpack loader development, so this might not be the right way to do it, but when I save the list of methods to workerize in the parse hook on the CACHE
object which is local to this loader, everything works. I'll make a PR with the change so you can see exactly what I mean.
from workerize-loader.
I have the follwing situation:
const worker = require('workerize-loader!./worker')
- Something of the dependencies of
./worker
is modified - the "empty" worker is hot-reloaded (
Uncaught TypeError: Object(...) is not a function
). - Then if I modify
./woker
itself (just put comment). It hot-reloads ok.
Is it this bug? Is it going to be fixed?
from workerize-loader.
Now I found the root fo the problem: the
__workerizeExports
property is not persisted on the compilation object between recompiles, resulting in an empty list of methods after the first compile. I know next to nothing about Webpack loader development, so this might not be the right way to do it, but when I save the list of methods to workerize in the parse hook on theCACHE
object which is local to this loader, everything works. I'll make a PR with the change so you can see exactly what I mean.
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.
from workerize-loader.
I'm having the same issue (no babel) when using together with ts-loader:
{ test: /\.worker\.ts$/, loaders: [ 'workerize-loader', 'ts-loader' ] }
test.worker.ts
export async function getArray() {
const arr: number[] = [ 1, 2, 3 ];
return arr;
}
the methods
array is empty and doesn't contain my getArray
function.
I'm not using babel or hot reload, any idea how to make this work with typescript compilation?
Once i remove ts-loader from the list it works fine (without typescript of course).
from workerize-loader.
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.
from workerize-loader.
Strange! What version of Webpack?
from workerize-loader.
@developit v3.10
I'm using a very basic setup. babel
followed by workerize-loader
from workerize-loader.
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.
from workerize-loader.
Ah interesting 1.0.1 works - I'll see if there's anything fishy in the diff.
from workerize-loader.
Looks like #26 is the culprit:
71b1df8#diff-1fdf421c05c1140f6d71444ea2b27638R20
from workerize-loader.
@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:
src/my.js
import MyWorker from 'workerize-loader!./MyWorker';
const worker = new MyWorker();
No changes to default webpack config were made
.babelrc
{
"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:
Worker {onmessage: null, onerror: null}
Hope that can help to identify issue. In near future I'll try to create a repository that reproduces the issue.
from workerize-loader.
Based on @developit suggestion to play around with webpack.hot
tried this solution.
In the file that proxies the worker getWorker.js
:
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;
};
from workerize-loader.
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 webpack-dev-server
restart helps. Any ideas?
from workerize-loader.
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.
from workerize-loader.
@exarus @developit @janbaykara I found the issue! Turning off babel-loader's cacheDirectory
option (set it to false) does the trick. This is enabled in CRA, and I assume most CRA derivatives like vue-cli.
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...
from workerize-loader.
@shayke Maybe it is not your ts-loader
plugin but your tsconfig.json
causes commonJS transform as described in the [About Babel] section in readme. Check if you have "module": "commonJS",
in tsconfig.json
. I encountered the same issue and make it work by modify this option to es6
(which requires additional modification because of ts check rule changed...)
from workerize-loader.
Related Issues (20)
- Load worker scripts from other domain (CORS) HOT 3
- Jest HOT 3
- importScripts HOT 3
- Works in development but 'npm run build' silently fails to add index.html and JS bundles to build folder HOT 2
- Workerize loader runs out of memory HOT 5
- workerize-loader with Parcel bundler HOT 1
- npm install -D workerize-loader HOT 1
- How to make the output worker js file under /static rather than root directory in Create React App? HOT 1
- Feature request: rollup usage HOT 1
- Memory leak / lack of GC on Android Chrome when using workerize-loader
- worker.terminate() does not terminate worker thread
- Customizing worker bundles name results in "worker" word in file twice.
- Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': function transformRequest(data, headers) { normalizeHeaderName(headers, 'Accept'); normalizeHeaderName(...<omitted>... } could not be cloned. HOT 1
- Uncaught TypeError: d is undefined
- FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory HOT 2
- FetchCompileWasmTemplatePlugin is not a constructor HOT 4
- Duplicate workers with inline and Webpack 5
- Duplicate worker code inside bundle file with inline option
- [path] replacer token passed to workerize-loader has stopped working in Webpack 5
- Breaks on latest gatsby, only when there is a webpack cache HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from workerize-loader.