#how to handle dependencies using node built-ins

6 messages · Page 1 of 1 (latest)

vague radish
#

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

#

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';
    ╵         ~~~~~
GitHub

Contribute to ionic-team/rollup-plugin-node-polyfills development by creating an account on GitHub.

#

✘ [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

GitHub

GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 330 million projects.

warm tree
#

Also, it looks like you are using an older config, back when wrangler still used Webpack for bundling

vague radish
#

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 🙂