Hey! I'm new to Cloudflare, and trying to convert my node server to work in Cloudflare workers instead. While my core code seems to work fine, I'm having issues with various dependencies that rely on node built-ins. I'm a bit confused as to how to handle these - is there a way to polyfill / compile with webpack or something more thorough than just the node_compat flag? Or for these packages require node:fs, node:util, node:stream should I just avoid entirely ? Will send the error message below
#how to handle dependencies using node built-ins
6 messages · Page 1 of 1 (latest)
yarn wrangler:dev
⛅️ wrangler 3.15.0
▲ [WARNING] Processing src/wrangler.toml configuration:
- 😶 Ignored: "type":
Most common features now work out of the box with wrangler, including modules, jsx,
typescript, etc. If you need anything more, use a custom build.
▲ [WARNING] Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
✘ [ERROR] No matching export in "node-modules-polyfills:fs" for import "statSync"
../node_modules/fetch-blob/from.js:1:9:
1 │ import { statSync, createReadStream, promises as fs } from 'node:fs'
╵ ~~~~~~~~
✘ [ERROR] No matching export in "node-modules-polyfills:fs" for import "createReadStream"
../node_modules/fetch-blob/from.js:1:19:
1 │ import { statSync, createReadStream, promises as fs } from 'node:fs'
╵ ~~~~~~~~~~~~~~~~
✘ [ERROR] No matching export in "node-modules-polyfills:fs" for import "promises"
../node_modules/fetch-blob/from.js:1:37:
1 │ import { statSync, createReadStream, promises as fs } from 'node:fs'
╵ ~~~~~~~~
✘ [ERROR] No matching export in "node-modules-polyfills:util" for import "types"
../node_modules/node-fetch/src/body.js:9:8:
9 │ import {types, deprecate, promisify} from 'node:util';
╵ ~~~~~
✘ [ERROR] No matching export in "node-modules-polyfills:util" for import "promisify"
../node_modules/node-fetch/src/body.js:9:26:
9 │ import {types, deprecate, promisify} from 'node:util';
╵ ~~~~~~~~~
✘ [ERROR] No matching export in "node-modules-polyfills:util" for import "types"
../node_modules/node-fetch/src/headers.js:7:8:
7 │ import {types} from 'node:util';
╵ ~~~~~
✘ [ERROR] No matching export in "node-modules-polyfills:stream" for import "pipeline"
../node_modules/node-fetch/src/index.js:12:29:
12 │ import Stream, {PassThrough, pipeline as pump} from 'node:stream';
╵ ~~~~~~~~
✘ [ERROR] No matching export in "node-modules-polyfills:net" for import "isIP"
../node_modules/node-fetch/src/utils/referrer.js:1:8:
1 │ import {isIP} from 'node:net';
╵ ~~~~
✘ [ERROR] No matching export in "node-modules-polyfills:url" for import "fileURLToPath"
../node_modules/trpc-panel/lib/index.mjs:2:9:
2 │ import { fileURLToPath } from 'node:url';
╵ ~~~~~~~~~~~~~
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ [b] open a browser, [d] open Devtools, [l] turn off local mode, [c] clear console, [x] to exit │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✘ [ERROR] Failed to build
If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose
Some of these node modules, like fs, just plain won't work on Workers. And node-fetch isn't needed, since Workers already has fetch. I would probably use a differnet package if possible.
Also, it looks like you are using an older config, back when wrangler still used Webpack for bundling
Thanks a ton for the response! Is there a wrangler doctor type of command that helps detect what packages are causing these errors? Or is it more of a trial and error thing just running wrangler + yarn why until I can get it working?
Appreciate your help 🙂