Worker custom bundle doesn't work properly with format='modules'

I am trying to build my worker using webpack. When i use service-worker syntax it bundles properly. But when i am trying to use an modules syntax i get an empty file and not able to run it.
Can someone help me to setup configs properly?

My webpack configs are:

module.exports = {
	target: 'webworker',
	entry: './src/worker.mjs',
	mode: 'production',
	output: {
		path: path.resolve(__dirname, 'dist'),
		filename: 'worker.js',
	},
	plugins: [
		new webpack.DefinePlugin({
			window: 'self',
		}),
	],
	resolve: {
		fallback: {
			// browser/worker polyfills required to replace Node libraries used by the jsC8 SDK
			url: require.resolve('url'),
			path: require.resolve('path-browserify'),
			http: require.resolve('stream-http'),
			https: require.resolve('https-browserify'),
			crypto: require.resolve('crypto-browserify'),
			buffer: require.resolve('buffer/'),
			stream: require.resolve('stream-browserify'),
		},
	},
};

and wrangler.toml is

[build]
command = "npm run build"

[build.upload]
format = "modules"

build command is ‘webpack --progress’