Cloudflare Worker Migration: Wrangler v1 to v3 with Webpack & Node.js Compatibility

What is the name of the modal you’re running?

none

What is the error number?

none

What is the error message?

Starting local server… ✘ [ERROR] service core:user:api-gateway-worker: Uncaught Error: Dynamic require of “node:stream” is not supported at null. (core:user:api-gateway-worker:15:11) at null. (core:user:api-gateway-worker:316:28) in …/.nvm/versions/node/v20.17.0/lib/node_modules/wrangler/node_modules/unenv/runtime/node/console/index.mjs at null. (core:user:api-gateway-worker:18:61) in __init at null. (core:user:api-gateway-worker:365:7) in …/.nvm/versions/node/v20.17.0/lib/node_modules/wrangler/node_modules/unenv/runtime/node/console/$cloudflare.mjs at null. (core:user:api-gateway-worker:18:61) in __init at null. (core:user:api-gateway-worker:415:7) in …/.nvm/versions/node/v20.17.0/lib/node_modules/wrangler/_virtual_unenv_global_polyfill-console.js at null. (core:user:api-gateway-worker:18:61) in __init at null. (core:user:api-gateway-worker:705:7) in …/.nvm/versions/node/v20

What is the issue or error you’re encountering

I’m trying to migrate my existing Cloudflare Worker code, built with Webpack for compatibility, from Wrangler v1 to v3. However, I keep encountering issues throughout the migration. The official documentation lacks a proper guide for v1 to v3 migration, and much of it isn’t up to date with Wrangler v3. When following some of the provided steps, I often run into compatibility problems, deprecated features, or version mismatches. Currently, I’m experiencing the above error

What steps have you taken to resolve the issue?

I’ve followed the available migration guides, read articles, and checked error posts online. Despite trying various steps, nothing has worked successfully.

What are the steps to reproduce the issue?

wrangler : 3.79.0
node: 20.17.0
npm: 10.8.2

Wrangler.toml:
name = “test-worker”
main =“./index.js”

workers_dev = true
compatibility_date = “2024-03-08”
compatibility_flags = [ “nodejs_compat_v2” ]

package.json:
{
“private”: true,
“name”: “test-worker”,
“version”: “1.0.0”,
“main”: “index.js”,
“dependencies”: {
@aws-sdk/client-dynamodb”: “^3.17.0”,
@aws-sdk/client-s3”: “^3.186.0”,
@tsndr/cloudflare-worker-jwt”: “^2.4.5”,
“fs-extra”: “^10.0.0”,
“image-blob-reduce”: “^4.1.0”
}
}

webapck.config.js:
module.exports = {
target: ‘webworker’,
entry: ‘./index.js’,
mode: ‘production’,
devtool: ‘source-map’,
}

webpack.config and package.json are file are from when they were used with v1,
I have updated wrangler.toml for v3.

Wrangler.toml (v1):
name = “test-worker”
type = “webpack”
workers_dev = true
webpack_config = “webpack.config.js”
compatibility_date = “2022-03-08”

Using these configuration when i try to run the code with command wrangler dev, above error occurs.

Screenshot of the error