Webpack. No event handlers were registered. This script does nothing.
I have prepared webpack.config.js
....
output: {
filename: "worker.js",
path: path.resolve(__dirname, "dist"),
library: 'webpack-test',
libraryTarget: 'commonjs2'
and receive webpack result in dist folder. Then I try to load this result to Cloudflare “wrangler deploy” with setup in TOML file of webpack result
...
main = "./dist/worker.js"
And receive this strange result
⛅️ wrangler 3.36.0
-------------------
Total Upload: 2.21 KiB / gzip: 0.96 KiB
X [ERROR] A request to the Cloudflare API (/accounts/879d75a301cfdc25c307469b83b91862/workers/scripts/webpack) failed.
No event handlers were registered. This script does nothing.
[code: 10021]
Why? What I done wrong? Or Webpack not applicable to Worker at all?
2 Replies
wrangler
used to use Webpack, but that was a long time ago. Now it natively supports esbuild
, but you can still bring your own bundler if you want
What does ./dist/worker.js
look like?@Hello, I’m Alastair! ./dist/worker.js looks fine: "(()=>{"use strict";var e={d:(t,o)=>{...}})}};module.exports["webpack-test"]=t})();" and without Webpack (directly from src directory) all working fine.
I do something wrong in my Webpack config?
require("dotenv").config();
const path = require("path");
const { DefinePlugin } = require("webpack");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
module.exports = {
infrastructureLogging: {
level: "verbose",
},
entry: path.resolve(dirname, "worker.js"),
target: "webworker",
output: {
filename: "worker.js",
path: path.resolve(dirname, "dist"),
library: 'webpack-test',
libraryTarget: 'commonjs2'
},
mode: "production",
resolve: {
fallback: {
fs: false,
},
},
plugins: [
new NodePolyfillPlugin(),
new DefinePlugin({
BOT_TOKEN: JSON.stringify(process.env.BOT_TOKEN ""),
SECRET_PATH: JSON.stringify(process.env.SECRET_PATH ""),
}),
],
performance: {
hints: false,
},
};