Comments (10)
For people exploring the Webpack 5 syntax:
const worker = new Worker(new URL("./my_worker.js", import.meta.url));
No extra plugin loading is required.
from worker-plugin.
FWIW Webpack 5 seems to have landed its own worker-plugin
, which I guess means this plugin shouldn't be used with it.
from worker-plugin.
Same for typescript
const worker = new Worker(new URL('./workers/foo.worker.ts', import.meta.url));
https://github.com/azangru/web-worker-ts-webpack-test/blob/master/src/index.ts#L11
from worker-plugin.
The function was removed in webpack/webpack#7781 (commit webpack/webpack@5553166)
from worker-plugin.
Yikes - I didn't know about this removal, thanks for looking into this.
I believe the following should work as a replacement for the usage, to support both Webpack 4 and 5:
let ModuleDecoratorDependency;
try {
ModuleDecoratorDependency = require("./dependencies/ModuleDecoratorDependency");
} catch (e) {}
// ... then replacing the above lines:
} else if (ModuleDecoratorDependency) {
const dep = new ModuleDecoratorDependency(
ParserHelpers.getModulePath(parser.state.module.context, loaderRequest),
parser.state.module
);
dep.loc = expr.loc;
parser.state.module.addDependency(dep);
}
} else {
// For CommonJS/Auto
const req = `require(${JSON.stringify(loaderRequest)})`;
ParserHelpers.toConstantDependency(parser, id)(expr.arguments[0]);
ParserHelpers.addParsedVariableToModule(parser, id, req);
}
from worker-plugin.
This is also an issue for me. I attempted to add your above code however the error persists.
from worker-plugin.
I wound up with a fresh error after making that change:
ERROR in ./src/development/client.js
Module parse failed: ParserHelpers.getModulePath is not a function
File was processed with these loaders:
* ../../../node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
TypeError: ParserHelpers.getModulePath is not a function
at /Users/daniel/Code/NY/choreographer/node_modules/worker-plugin/src/index.js:123:29
at Hook.eval (eval at create (/Users/daniel/Code/NY/choreographer/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:16)
at Hook.CALL_DELEGATE [as _call] (/Users/daniel/Code/NY/choreographer/node_modules/webpack/node_modules/tapable/lib/Hook.js:14:14)
at JavascriptParser.callHooksForInfoWithFallback (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:2871:24)
at JavascriptParser.callHooksForExpressionWithFallback (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:2782:16)
at JavascriptParser.callHooksForExpression (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:2750:15)
at JavascriptParser.walkNewExpression (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:2457:23)
at JavascriptParser.walkExpression (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:2185:10)
at JavascriptParser.walkVariableDeclaration (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:2007:33)
at JavascriptParser.walkStatement (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:1528:10)
Did a little digging in the Webpack sources; couldn't find anything germane.
from worker-plugin.
Oh wow, thanks! Totally missed that.
from worker-plugin.
I was playing around with Webpack 5 + esbuild and now I think I'm clearly missing this plugin. The issue is that Webpack is now relying on import.meta.url
which is not always available depending on your loader and on the selected target, see webpack/webpack#11439 (comment).
from worker-plugin.
Unfortunately, Webpack5's Web Worker solution relies on import.meta.url
, which is not compatible friendly.
from worker-plugin.
Related Issues (20)
- Warnings in terminal when using with vue cli (eslint + prettier configured) HOT 1
- parser.state.module.addPresentationalDependency is not a function HOT 3
- worker-plugin loader dependency not found
- Start ShareWorker from Worker
- Webpack 5: import declarations may only appeaar at the top level of a module HOT 2
- Deprecation warning with webpack 5.42.0 HOT 1
- Using environment variables HOT 1
- entries[0].files.values is not a function
- Vue2 + Webpack not bundling? HOT 2
- Multiple functions inside a worker not supported? HOT 2
- Nested workers not resolved correctly output.publicPath is relative HOT 5
- vue use work-plugin. Error HOT 5
- Failed to using 'importScripts' on *worker.js HOT 1
- webpack build fails
- Error when using NPM module with Rollup worker bundled HOT 3
- ESLint errors for code injected by Babel HOT 6
- Angular 10, webpack, worker loader, large project HOT 3
- Are there similar plugin that support worklet? HOT 1
- SingleEntryPlugin has been removed from webpack
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 worker-plugin.